Reputation: 1799
There are a bazillion examples online of doing redirects via apache's htaccess, but I can't find any example of redirecting a full URL match to another full URL.
For instance, I have an existing website at
https://example.com
How do I redirect some specific URLs for that domain to a different one:
https://example.com/login --> https://my.example.com/login
https://example.com/register --> https://my.example.com/register
For every other every other path on example.com I need to remain untouched so my site still works fine (i.e. /blog
shouldn't redirect somewhere else).
Upvotes: 1
Views: 1540
Reputation: 41219
You can use the following :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(login|register)/?$ http://my.example.com/$1 [L,R]
This will redirect example.com/login
or example.com/register
to http://my.example.com/
You can alternatively accomplish this using the RedirectMatch
directive (if the newurl is on a diffrent webserver) :
RedirectMatch ^/(login|register)/?$ http://my.example.com/$1
Upvotes: 1