代码之家  ›  专栏  ›  技术社区  ›  braveterry

如何将这个Apache重写规则转换为tucky UrlRewriteFilter规则?

  •  3
  • braveterry  · 技术社区  · 14 年前

    <IfModule rewrite_module>
         RewriteEngine on
         RewriteMap tolowercase int:tolower
         RewriteCond $2 [A-Z] 
         RewriteRule ^(.*)/(.*).html$ $1/${tolowercase:$2}.html [R=301,L]
    </IfModule>
    

    这就改变了:

    http://localhost.localdomain.com/FooBarBaz.html
    

    http://localhost.localdomain.com/foobarbaz.html
    

    我想把它移植到这个塔基.org URL Rewrite Filter .

    我可以使用什么等效规则使URL变为小写?我对如何形成条件元素特别感兴趣。

    <rule>
        <name>Force URL filenames to lower case</name>
        <from>^(.*)/(.*).html$</from>
        <to type="permanent-redirect" last="true">$1/${lower:$2}.html</to>
    </rule>
    
    2 回复  |  直到 12 年前
        1
  •  4
  •   braveterry    14 年前

    <rule match-type="regex">
        <name>Force URL filenames to lower case</name>
        <condition type="request-uri" casesensitive="false" operator="notequal">^.*/a4j.*$</condition>
        <condition type="request-uri" casesensitive="true">^.*/.*[A-Z].*.html$</condition>
        <from>^(.*)/(.*).html$</from>
        <to type="permanent-redirect" last="true">$1/${lower:$2}.html</to>
    </rule>
    

    第一个条件是防止规则在a4jax请求上运行。

        2
  •  1
  •   Sirius_B    11 年前

    肖恩,

    这样做不需要条件(AJAX调用上的ignore除外)。更重要的是,条件元素 does not have a casesensitive attribute ,只有from元素可以。一旦我意识到这一点,我就可以把规则写成:

    <rule match-type="regex">  
        <note>Force URL to lower case</note>
        <from casesensitive="true">^.*[A-Z].*$</from>
        <to type="permanent-redirect" last="true">${lower:$0}</to>  
    </rule>
    

    注意:这适用于整个路径请求(但不适用于querystring)。

    我偶然发现了你的帖子,因为给我的URL重写过滤规则看起来很像你的,但它不起作用。通过大量的尝试和错误,我最终发现问题根本不是正则表达式的问题。是这样的 区分大小写,所以我得到了无限的重定向。