Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mod_rewrite to redirect home page ONLY

I have a website that needs redirected, but I can't just redirect the / directory because there are other websites in folders on the server, and doing that redirects them as well. NOT GOOD!

So I have my .htaccess file with a bunch of 301 redirects for individual HTML pages, and those work fine. But I need to redirect the home page. Here is what I have to do that:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^recherchegoldens.com [NC]
RewriteRule ^(.*)$ http://whitegoldenretriever.com/$1 [R=301,L]

That forwards the home page, great. But it also messes up my other 301 redirects. Here is one of my redirects:

Redirect 301 /Available-Pups.html http://www.whitegoldenretriever.com/available-pups/

But with the rewrite rule above, if I type in recherchgoldens.com/Available-Pups.html, it just forwards to whitegoldenretriever.com/Available-Pups.html

But I don't want that. I want it to still forward to the location set in my Redirect 301 directive.

What am I doing wrong?

like image 961
Brent Randall Avatar asked Jan 17 '26 02:01

Brent Randall


1 Answers

To redirect only home page use:

RewriteCond %{HTTP_HOST} ^recherchegoldens\.com$ [NC]
RewriteRule ^/?$ http://whitegoldenretriever.com/ [R=301,L]

Make sure to test this in a new browser to avoid old browser cache.

like image 100
anubhava Avatar answered Jan 19 '26 18:01

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!