如何将这个Apache Rewrite规则转换为Tuckey UrlRewriteFilter规则?

3
我有以下的Apache Rewrite规则。
<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

我希望将其移植到tuckey.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个回答

4

这是我最终选择的方案:

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

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

1

Sean,

您不需要条件来执行此操作(除了 AJAX 调用中的忽略)。更重要的是,条件元素 没有区分大小写属性,只有 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>

注意:此方法适用于整个路径请求(但不包括查询字符串)。

我偶然看到了您的帖子,因为给我的URL Rewrite Filter规则与您的很像,但却不能正常工作。通过大量的尝试和错误,最终我发现问题并不在于正则表达式本身,而是因为它 匹配 了,但是却不区分大小写,所以会导致无限重定向。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接