【问题标题】:IIRF redirect combine rules?IIRF重定向组合规则?
【发布时间】:2009-11-18 22:03:33
【问题描述】:

我有 3 条“规则”。一个确保 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]

【问题讨论】:

    标签: url mod-rewrite rewrite iirf


    【解决方案1】:

    on the IIRF Forums 这个问题有一个很好的答案。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        不幸的是,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 中执行此操作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-07-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-08-27
          相关资源
          最近更新 更多