[英]IIS-URL Rewrite, URL rule to lowercase except querystring
嗨,我在IIS中使用URL重寫模塊。 我會創建一個規則來轉換小寫網址。 但是,我遇到了問題。 我的目標是做到以下幾點:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/app/action?X=1&y=3&JJ=3...
我的第一次失敗嘗試是:
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
結果:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/App/ActIon?X=1&y=3&JJ=3...
它只適用於域(因為URL變量只有域)
我的第二次失敗嘗試是:
<rule name="Convert to lower case" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>
結果:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/app/action?x=1&y=3&jj=3...
這也適用於查詢字符串。 因此我沒有為我服務。
我的第三次失敗嘗試是:
<rule name="Convert to lower case" stopProcessing="true">
<match url="^(.*[A-Z].*)(\/.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
</rule>
結果:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/app/ActIon?X=1&y=3&JJ=3...
這個問題不適用於最后一條路徑。
這導致我不需要滿足以下規則:
http://www.doMain.com/App => http://www.domain.com/app
問題:
是否有任何規則允許我做我需要的事情?
這個模塊是否正確?
因為我有另一種選擇是使用ASP.NET路由引擎(例如https://github.com/schourode/canonicalize )
只需要一點修改:打破網址?
將文件名部分與查詢字符串分開。
<rule name="Convert to lower case" stopProcessing="true">
<match url="^([^?]*[A-Z][^?]*)(\?.*)?" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
</rule>
如果你使用哈希( #
),你可能也應該打破它們,因為你不想強迫它們小寫。
<rule name="Convert to lower case" stopProcessing="true">
<match url="^([^?#]*[A-Z][^?#]*)(\?.*)?(#.*)?" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}{R:3}" redirectType="Permanent" />
</rule>
復雜的正則表達式不是必需的
<rule name="Convert to lower case" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect"
url="http://{ToLower:{HTTP_HOST}{PATH_INFO}}"
redirectType="Permanent" />
</rule>
Querystring不包含在匹配中,默認情況下會附加到重定向URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.