HTACCESS如何优先级重写
我们最近迁移了新网站,我们需要调整HTACCESS,以避免使用搜索引擎的404错误,
该网站是一个多语言网站,我们决定使用Session和Cookie来管理多语言而不是字符串。
我们将HTACCESS组合在一起,以进行更改,
以下以下此代码下方的HTACCESS代码
RewriteEngine On
RewriteRule ^([^/]+)/fr/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/en/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/es/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/pt/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/ar/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^/?ar(.*)$ /$1 [L,R=301]
RewriteRule ^/?pt(.*)$ /$1 [L,R=301]
RewriteRule ^/?es(.*)$ /$1 [L,R=301]
RewriteRule ^/?fr(.*)$ /$1 [L,R=301]
RewriteRule ^/?en(.*)$ /$1 [L,R=301]
RewriteRule ^/?location(.*)/(.*).html$ /newlocation$1/$2.html$3 [R=301,NE,L]
RewriteRule ^/?ads/location(.*)/(.*).html$ /ads/newlocation$1/$2.html$3 [R=301,NE,L]
RewriteRule ^/?page(.*)/(.*).html$ /newpage$1/$2.html$3 [R=301,NE,L]
RewriteRule ^/?ads/page(.*)/(.*).html$ /ads/newpage$1/$2.html$3 [R=301,NE,L]
非常有效!但是,当我在下面添加此代码时,
RewriteCond %{REQUEST_URI} !^/ads/
RewriteRule ^([^/]+)\.html?(.*)$ /ads/$1.html$2 [L,QSA]
什么都没有起作用了。这有什么问题吗?
We recently migrate our new website and we need to adjust htaccess to avoid 404 error with the search engine,
The website was a Multilanguage site we decided to use session and cookie to manage multi language instead of string.
We put together htaccess to make the changes
I have my htaccess code below
RewriteEngine On
RewriteRule ^([^/]+)/fr/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/en/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/es/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/pt/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^([^/]+)/ar/?(.*)$ /$1/$2 [R=301,NE,L]
RewriteRule ^/?ar(.*)$ /$1 [L,R=301]
RewriteRule ^/?pt(.*)$ /$1 [L,R=301]
RewriteRule ^/?es(.*)$ /$1 [L,R=301]
RewriteRule ^/?fr(.*)$ /$1 [L,R=301]
RewriteRule ^/?en(.*)$ /$1 [L,R=301]
RewriteRule ^/?location(.*)/(.*).html$ /newlocation$1/$2.html$3 [R=301,NE,L]
RewriteRule ^/?ads/location(.*)/(.*).html$ /ads/newlocation$1/$2.html$3 [R=301,NE,L]
RewriteRule ^/?page(.*)/(.*).html$ /newpage$1/$2.html$3 [R=301,NE,L]
RewriteRule ^/?ads/page(.*)/(.*).html$ /ads/newpage$1/$2.html$3 [R=301,NE,L]
this code above works great ! but when I add this code below,
RewriteCond %{REQUEST_URI} !^/ads/
RewriteRule ^([^/]+)\.html?(.*)$ /ads/$1.html$2 [L,QSA]
Nothing is working anymore. Is there anything wrong with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您显示的样本,请尝试遵循HTACCESS规则文件。在测试URL之前,请确保清除浏览器缓存。我已经在新规则(在您显示的HTACCESS文件的底部)提出了评论,请确保仅此规则。在HTACCESS中,规则的地点也非常重要。
With your shown samples, please try following htaccess rules file. Please make sure to clear your browser cache before testing your URLs. I have put comments before new rules(at the bottom of your shown htaccess file), make sure these rules are there only. Place of rules is also very important in htaccess.