我有三条“规则”。一种是确保URL是小写的,另一种是在目录末尾包含一个斜杠,第三种是强制通过目录访问index.html页面。
问题在于,有时这会导致多个301重定向。我真的希望每条规则依次适用,如果必要的话,再转一次到最终的url。例如,url可能需要转换为小写,并添加一个斜杠。或者可能需要降低index.html并将其更改为目录。
知道我该怎么做吗?非常感谢。
规则如下:
#LOWERCASE URLS For Directories, aspx, html files
RedirectRule ^/(.*[A-Z].*(/|\.html|\.aspx))$ /#L$1#E [R=301]
#ADD SLASH TO DIRECTORIES
#---------------------------------------------
#Perm Redirect If:
#Starts w/ Forward Slash
#Match Any Characters Except (. or ?) 1 or more times
#End w/ someting besides a dot, ?, or slash
#If So, Perm Redirect captured piece W/ Slash At End and at front
RedirectRule ^/([^.?]+[^.?/])$ /$1/ [I,R=301]
#CHANGE INDEX.HTML REQUESTS TO DIRECTORY REQUESTS
#---------------------------------------------
RedirectRule ^/(.*)/index\.html$ /$1/ [I,R=301]发布于 2010-04-04 04:14:40
对于这个问题,在IIRF论坛上有一个很好的答案。
发布于 2009-11-19 14:48:37
我只看到了把后两者结合起来的机会:
RedirectRule ^/([^A-Z?]*[A-Z].*(/|\.html|\.aspx))$ /#L$1#E [R=301]
RedirectRule ^/([^.?]+?[^.?/])(/index\.html)?$ /$1/ [I,R=301]发布于 2016-09-08 20:53:22
不幸的是,IIRF论坛的回应并没有解决多重重定向问题。每个规则仍然会导致自己的重定向。
使用没有重定向标志的RewriteRule而不是RedirectRule会引发IIRF状态中的错误:
# rule:
# force HTTPS [disable on dev site until port 80 and port 443 served by same site]
# after rewrite continue with remaining tests
RewriteCond %{HTTPS} off
RewriteRule ^/(.*)$ https://www.example.com/$1 [NC]错误: C:\Inetpub\wwwroot\example-com\www\Iirf.ini(26):警告:重写到完全限定的URL.可能是错的。你可能想要RedirectRule或ProxyPass。
我曾料到IIRF会获得这个规则的结果,并再次通过IIRF规则将其发回,获取沿途的任何其他URL修改,并最终发送一个301重定向回浏览器,最终得到所有重写的最终结果。据我所知,N标志在mod_rewrite中实现了这一点。
https://stackoverflow.com/questions/1759446
复制相似问题