Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

301/302 redirect from slash root to specific home page url

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. ;)

like image 379
Sahus Pilwal Avatar asked Jun 28 '12 12:06

Sahus Pilwal


2 Answers

Use this line:

RedirectMatch 302 ^/$ /home/

To make sure only root is redirected to /home/

like image 129
anubhava Avatar answered Oct 16 '22 13:10

anubhava


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/
like image 37
Salman A Avatar answered Oct 16 '22 12:10

Salman A