Reputation: 583
I would like to redirect a top level page using htaccess, but not redirect tier pages. Let me explain. I currently have this redirect in place:
Redirect 301 /support /donate
In summary, I want someone to be redirected to /donate
when the visit /support
. However, with this rule if someone visits:
https://www.example.com/support/test
They are redirected to:
https://www.example.com/donate/test
I do NOT want them to be redirected in these instances - only if they visit /support
or /support/
(note trailing slash).
I'm not sure how to do this or if this is possible. Any ideas?
Upvotes: 1
Views: 87
Reputation: 45968
The Redirect
directive is prefix-matching, so you will need to use the RedirectMatch
directive instead, which matches against a regex.
For example:
RedirectMatch 301 ^/support/?$ /donate
The above matches /support
or /support/
only and redirects to /donate
in both cases. Note that the previous Redirect
directive would have redirected to /donate
or /donate/
depending on whether there was a trailing slash on the initial request.
You will need to clear your browser cache before testing, since any erroneous 301 (permanent) redirects will have been cached persistently by the browser. Test first with 302s to avoid potential caching issues.
Reference:
Upvotes: 0