IIRF重定向组合规则?
我有3条“规则”。一是确保 URL 为小写,二是在目录末尾包含斜杠,三是强制通过目录访问 index.html 页面。
我的问题是,有时这会导致多个 301 重定向。我真的希望每个规则依次应用,然后在必要时重定向到最终网址。例如,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]
I have 3 "rules". One to make sure URLs are lowercase another to include a slash at the end of directories, and a 3rd to force access to index.html pages to be thru the directory instead.
The problem w/ how I have it is, sometimes this is causing multiple 301 redirects. I'd really like each rule to apply in turn and then if neccessary redirect once to the final url. For example a url might need to be converted to lowercase and have a slash added.
Or may need to be lowecase and change from index.html to a directory.
Any ideas how I can do this? Thanks very much.
The rules are below:
#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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IIRF 论坛对此问题有一个很好的答案。
There's an excellent answer to this question on the IIRF Forums.
我只看到将后两者结合起来的机会:
I only see the chance to combine the latter two:
不幸的是,IIRF 论坛上的回复并没有解决多重重定向问题。每个规则仍然会导致其自己的重定向。
使用 RewriteRule [不带重定向标志] 而不是 RedirectRule 会在 IIRF 状态中引发错误:
error:
C:\Inetpub\wwwroot\example-com\www\Iirf.ini(26):警告:重写为完全限定的 URL。可能是错的。您可能需要 RedirectRule 或 ProxyPass。
我预计 IIRF 会获取此规则的结果,并再次通过 IIRF 规则将其发送回,沿途拾取任何其他 URL 修改,并最终将单个 301 重定向发送回浏览器,最终结果为全部重写。据我了解,[N] 标志在 mod_rewrite 中执行此操作。
unfortunately, the response on the IIRF forums does not solve the multiple redirect issue. each rule still causes its own redirect.
using a RewriteRule [without a redirect flag] instead of a RedirectRule throws an error in IIRF status:
error:
C:\Inetpub\wwwroot\example-com\www\Iirf.ini(26): WARNING: Rewriting to a fully-qualified URL. Probably wrong. You may want RedirectRule or ProxyPass.
I'd anticipated that IIRF would have taken the results of this rule and sent it back through the IIRF rules again, pickup up any other URL modifications along the way, and ultimately sending a single 301 redirect back to the browser with the final result of all rewrites. The [N] flag does this in mod_rewrite, from what I understand.