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重寫過濾規則看起來很像你的工作。通過大量的試驗和錯誤,我終於發現問題不在於正則表達式。這是它匹配,但是不是區分大小寫,所以我得到無限的重定向。