Sahus Pilwal
Sahus Pilwal

Reputation: 97

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

Upvotes: 5

Views: 4889

Answers (2)

Salman Arshad
Salman Arshad

Reputation: 272106

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/

Upvotes: 5

anubhava
anubhava

Reputation: 785098

Use this line:

RedirectMatch 302 ^/$ /home/

To make sure only root is redirected to /home/

Upvotes: 10

Related Questions