I have been asked by my client's SEO agency to perform a 302 redirect on the home page of their website to the more specific URL of the same page i.e. (not the slash root version). This is a WordPress site running on Apache2 with .htaccess file in place. I need to achieve the following:
Redirect from:
http://www.example.com/
302 redirect to:
http://www.example.com/home/
I thought I could do this:
redirect 302 / http://www.example.com/home/
But of course this redirects everything to that url. So I guess I need some sort of regular expression but not sure how to produce the desired effect? Could anyone point me in the right direction? Any feedback greatly appreciated. ;)
Use this line:
RedirectMatch 302 ^/$ /home/
To make sure only root is redirected to /home/
The Redirect
directive uses prefix matching, so the rule mentioned in your question matches all URLs that start with /
... i mean ALL. RedirectMatch
should be used in this case:
This directive is equivalent to Redirect, but makes use of regular expressions, instead of simple prefix matching.
So this is what you need to do:
RedirectMatch temp ^/$ /home/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With