替代htaccess中的批量重定向301

时间:2017-11-09 05:50:19

标签: apache .htaccess redirect mod-rewrite

我在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

1 个答案:

答案 0 :(得分:1)

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

RewriteEngine On

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

(?!en/)是断言预告称URI尚未以/en/开头。