IIRF重定向组合规则?

发布于 2024-08-11 09:52:58 字数 855 浏览 9 评论 0原文

我有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

老街孤人 2024-08-18 09:52:58

IIRF 论坛对此问题有一个很好的答案。

There's an excellent answer to this question on the IIRF Forums.

梦途 2024-08-18 09:52:58

我只看到将后两者结合起来的机会:

RedirectRule ^/([^A-Z?]*[A-Z].*(/|\.html|\.aspx))$  /#L$1#E [R=301]
RedirectRule ^/([^.?]+?[^.?/])(/index\.html)?$ /$1/ [I,R=301]

I only see the chance to combine the latter two:

RedirectRule ^/([^A-Z?]*[A-Z].*(/|\.html|\.aspx))$  /#L$1#E [R=301]
RedirectRule ^/([^.?]+?[^.?/])(/index\.html)?$ /$1/ [I,R=301]
情深如许 2024-08-18 09:52:58

不幸的是,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]

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:

# 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]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文