【问题标题】:Using mod_rewrite to redirect home page ONLY仅使用 mod_rewrite 重定向主页
【发布时间】:2023-03-11 06:25:02
【问题描述】:

我有一个需要重定向的网站,但我不能只重定向 / 目录,因为服务器上的文件夹中还有其他网站,这样做也会重定向它们。不好!

所以我有我的 .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 指令中设置的位置。

我做错了什么?

【问题讨论】:

    标签: regex apache .htaccess redirect mod-rewrite


    【解决方案1】:

    仅重定向主页使用:

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

    请务必在新浏览器中进行测试以避免旧浏览器缓存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      相关资源
      最近更新 更多