【问题标题】:htaccess 301 redirect to new page is not workinghtaccess 301 重定向到新页面不起作用
【发布时间】:2019-06-04 20:01:19
【问题描述】:

我已将 60 301 从旧网址重定向到新网址。我在每个页面上做的语法是这样的:

Redirect 301 "http://www.olddomain.com/product/foo" "https://newdomain.com/product/bar"

当我转到旧页面 "http://www.olddomain.com/product/foo" 时,我被重定向到新页面,但不是我定义的 URL:"https://newdomain.com/product/bar"。我被重定向到"https://newdomain/product/foo"

所以重定向到域是正确的,但是URL上的子页面是旧的,而不是新的。

有人知道为什么会这样吗?

【问题讨论】:

    标签: apache .htaccess tomcat


    【解决方案1】:

    您无法匹配Redirect 指令中的域名。

    我建议使用mod_rewrite 规则,它应该放在所有其他规则之前

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
    RewriteRule ^product/foo/?$ https://newdomain.com/product/bar [L,NC,R=301]
    

    确保这是最重要的规则,并在全新的浏览器中对其进行测试以避免获取旧缓存。

    【讨论】:

      猜你喜欢
      • 2013-04-06
      • 2017-06-30
      • 2014-07-05
      • 2014-12-21
      • 2011-03-08
      • 2020-04-29
      • 2012-10-11
      相关资源
      最近更新 更多