How do I write IIS Rewrite rule if path does not have query string and any capital letter exists in path then redirect to same path with lower case
?
eg
http://localhost:62871/Second.aspx/Test?X=Y
redirects to: http://localhost:62871/second.aspx/test?X=Y
Following rule works but it lower cases the querystring too:
<rewrite>
<rules>
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
</rules>
</rewrite>
The variable URL
contains the entire url - so ToLower
is lower casing the entire url.
To get the desired behaviour you need to create the action
's url manually from multiple server variables.
Available variables include {HTTP_HOST}
, {PATH_INFO}
and {QUERY_STRING}
, you can then apply the lowercase function to whichever variables you require.
When creating the final url you also need to include the seperators :
, /
, ?
between the variables to get a valid url.
See this page for quick overview of variables: https://weblogs.asp.net/owscott/url-parts-available-to-url-rewrite-rules
See here for full rewrite module docs: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.