- 1 year ago
URL Rewrite rule IIS with special character
When creating URL Rewrite rules in IIS, special characters must be properly escaped using URL encoding to ensure that the rule works correctly.
To escape special characters in a URL Rewrite rule, you can use the %
symbol followed by the hexadecimal code for the character. For example, to escape the #
character, you would use %23
.
Here is an example URL Rewrite rule that uses a special character:
php<rule name="Redirect with Special Character" stopProcessing="true">
<match url="example/#page" />
<action type="Redirect" url="https://www.example.com/page.aspx" />
</rule>
In this example, the #
character is escaped using %23
in the match
element to ensure that the rule matches the correct URL. The action
element redirects the user to the page.aspx
page on the www.example.com
domain.
Note that if you are using URL Rewrite rules in a web.config file, you may need to use double percent signs (%%
) to escape special characters in the file. For example, to escape the #
character in a web.config file, you would use %25%23
.
Also note that if you are using special characters in the path or query string of a URL, you may need to use URL encoding in the target URL specified in the action
element of the rule as well.