Reputation: 55
I have the basic rewrite rule for my web.config file that transforms my urls to lowercase.
Perfect except for one issue: I pass tokens that are case sensitive in my emails that allow users to change their username/emails
How can I make a rewrite rule that makes my url lowercase while having the querystring remain case sensitive?
Example:
<rule name="Convert to lower case" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>
Makes this Url: http://resources.championscentre.org/ConfirmChangeEmail/abcDEfGhIJKlmn
Into This: http://resources.championscentre.org/confirmchangeemail/abcdefghijklmn
But needs to be: http://resources.championscentre.org/confirmchangeemail/abcDEfGhIJKlmn
Upvotes: 1
Views: 1606
Reputation: 26667
The regular expression should be
^[\w:\/\.]*\/
\w is [a-zA-Z0-9]
^
anchors the begining.
^[\w:\/\.]*
mathes any alpha number or /
or :
or .
/
at the end ensures that the last /
is selected. (assuming that your URL doesnt ends with /)
<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>
Upvotes: 2