我有一个需要重定向的网站,但我不能只重定向/目录,因为服务器上的文件夹中还有其他网站,这样做也会重定向它们。不好!</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]
请务必在新浏览器中进行测试以避免旧浏览器缓存。
关于regex - 仅使用 mod_rewrite 重定向主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038533/