3

我有以下的Apache重写规则如何将此Apache Rewrite规则转换为Tuckey UrlRewriteFilter规则?

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

回答

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

肖恩,

你并不需要的条件要做到这一点(除了在AJAX调用忽略)。更重要的是,条件元素does not have a casesensitive attribute,仅来自元素。当我意识到这一点,我能写的规则为:

<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重写过滤规则看起来很像你的工作。通过大量的试验和错误,我终于发现问题不在于正则表达式。这是它匹配,但是不是区分大小写,所以我得到无限的重定向。