patternMinor
Mapping several URLs to one login page
Viewed 0 times
loginseveralonepagemappingurls
Problem
My htaccess has this block in it:
How do I consolidate this block? The objective is to point to
RewriteRule ^login$ _user/login.php
RewriteRule ^login\.php$ _user/login.php
RewriteRule ^_user/login$ _user/login.php
RewriteRule ^_user/login\.php$ _user/login.phpHow 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:
In a regular expression,
The four cases can be combined into one rule:
RewriteRule ^(_user/)?login(\.php)?$ _user/login.phpIn 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.phpContext
StackExchange Code Review Q#96564, answer score: 4
Revisions (0)
No revisions yet.