如何将此Apache重写规则转换为Tuckey UrlrewriteFilter规则?
-
01-10-2019 - |
题
我有以下Apache重写规则
<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重写过滤器.
我可以用来制作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>
解决方案
这是我最终解决的问题:
<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请求上运行。
其他提示
肖恩,
您不需要条件来执行此操作(除了AJAX调用上的忽略外)。更重要的是,条件元素 没有病例敏感的属性, ,只有来自元素才能。一旦我意识到这一点,我就能将规则写为:
<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重写过滤器规则看起来很像您的工作不起作用。通过大量的反复试验,我最终发现问题根本不是正则表达式。是 曾是 匹配但曾经 不是 病例敏感,所以我得到了无限的重定向。
不隶属于 StackOverflow