仅使用mod_rewrite重定向主页 [英] Using mod_rewrite to redirect home page ONLY
问题描述
我有一个需要重定向的网站,但是我不能仅仅重定向/目录,因为服务器上的文件夹中还有其他网站,这样做也将它们重定向.不好!</p>
因此,我拥有.htaccess文件,其中包含针对单个HTML页面的一堆301重定向,这些文件都可以正常工作.但是我需要重定向主页.这是我要做的:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^recherchegoldens.com [NC]
RewriteRule ^(.*)$ http://whitegoldenretriever.com/$1 [R=301,L]
可以转发主页,太好了.但这也弄乱了我的其他301重定向.这是我的重定向之一:
Redirect 301 /Available-Pups.html http://www.whitegoldenretriever.com/available-pups/
但是根据上面的重写规则,如果我输入recherchgoldens.com/Available-Pups.html,它只会转发到whitegoldenretriever.com/Available-Pups.html
但是我不想要那样.我希望它仍然转发到我在Redirect 301指令中设置的位置.
我在做什么错了?
仅重定向首页,请使用:
RewriteCond %{HTTP_HOST} ^recherchegoldens\.com$ [NC]
RewriteRule ^/?$ http://whitegoldenretriever.com/ [R=301,L]
请确保在新的浏览器中对此进行测试,以避免旧的浏览器缓存.
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?
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.
这篇关于仅使用mod_rewrite重定向主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!