How to convert url to lowercase in iis

Christoph-2414 20 Reputation points
2023-09-19T14:03:36.84+00:00

Due to some requirements, I need to convert all urls to lowercase,

for example: http://aaa/Better/?aspx=aHR0cHM6Ly9hdXRo,

now, I want to convert it to http://aaa/better/?aspx=ahr0chm6ly9hdxro,

how can I do it?

Internet Information Services
0 comments No comments
{count} votes

Accepted answer
  1. Sam Wu-MSFT 7,046 Reputation points Microsoft Vendor
    2023-09-20T03:51:20.87+00:00

    @Christoph-2414

    You can try this rule:

    <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>
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sreeju Nair 11,856 Reputation points
    2023-09-19T14:37:41.2733333+00:00

    Hi Christoph-2414,

    You can use URL Rewrite Module to rewrite the URLs as per your requirements. To find more about URL Rewrite module and see how you can configure it, please follow the below URL

    https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    You may find the following string function reference already available in the document.

    There are three string functions available for changing the values within a rewrite rule action, as well as any conditions

    • ToLower - returns the input string converted to lower case.
    • UrlEncode - returns the input string converted to URL-encoded format. This function can be used if the substitution URL in rewrite rule contains special characters (for example non-ASCII or URI-unsafe characters).
    • UrlDecode - decodes the URL-encoded input string. This function can be used to decode a condition input before matching it against a pattern.

    Refer an example below.

    <rule name="Redirect to canonical url">
     <match url="^(.+)" /> <!-- rule back-reference is captured here -->
     <conditions>
      <!-- Check whether the requested domain is in canonical form -->
      <add input="{HTTP_HOST}" type="Pattern" pattern="^www\.mysite\.com$" negate="true" /> 
     </conditions>
     <!-- Redirect to canonical url and convert URL path to lowercase -->
     <action type="Redirect" url="http://www.mysite.com/{ToLower:{R:1}}" redirectType="Found" />
    </rule>
    
    

    Hope this helps