HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Mapping several URLs to one login page

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
loginseveralonepagemappingurls

Problem

My htaccess has this block in it:

RewriteRule ^login$ _user/login.php
RewriteRule ^login\.php$ _user/login.php
RewriteRule ^_user/login$ _user/login.php
RewriteRule ^_user/login\.php$ _user/login.php


How do I consolidate this block? The objective is to point to _user/login.php regardless of where on the server it's called from.

Solution

The last rule is completely superfluous, but harmless: it just maps the desired URL to itself.

The four cases can be combined into one rule:

RewriteRule ^(_user/)?login(\.php)?$ _user/login.php


In a regular expression, (something)? makes the something optional. That is, whether the URL starts with _user/ or not, and whether the URL ends with .php or not, it will get mapped to the desired login page.

Code Snippets

RewriteRule ^(_user/)?login(\.php)?$ _user/login.php

Context

StackExchange Code Review Q#96564, answer score: 4

Revisions (0)

No revisions yet.