【问题标题】:Alternative for bulk Redirect 301 in htaccesshtaccess 中批量重定向 301 的替代方案
【发布时间】:2017-11-09 16:08:28
【问题描述】:

我在 htaccess 中有一些链接重定向,其中每个链接都应在 .com 之后添加 /en,即

mydomain.com、mydomain.com/abc.html

mydomain.com/en, mydomain.com/en/abc.html

经过一些研究,我发现重定向 301 可以做到这一点。但我认为这不是完美和永久的解决方案。将来如果我添加另一个 URL,我必须再次将它添加到 htaccess。那么任何人都可以帮助我找到完美且永久的解决方案。

我已经在我的 htaccess 中完成了这个

Redirect 301 /about.html /en/about.html
Redirect 301 /contact-us.html /en/contact-us.html
Redirect 301 /index.html /en/index.html
Redirect 301 /locations.html /en/locations.html

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此单一重定向规则:

    RewriteEngine On
    
    RewriteRule ^(?!en/)(.+\.html)$ /en/$1 [L,NC,NE,R=301]
    

    (?!en/) 是否定先行断言 URI 尚未以 /en/ 开头。

    【讨论】:

    • 感谢您的回复,它有效,但是对于一个 URL,它添加更多的 '/en' 几乎是 20 '/en' s....可能是什么问题
    • 从新浏览器测试以避免缓存。还提供一个导致问题的示例 URL。
    猜你喜欢
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2014-11-25
    • 2011-05-01
    • 2011-01-03
    相关资源
    最近更新 更多