IIS 7.5 URL rewrite code

I have the following rewrite rule in web.config:

<rewrite> <rules> <rule name="Search" stopProcessing="true"> <match url="^search/(.+)$" /> <action type="Redirect" url="?q={R:1}" /> </rule> </rules> </rewrite> 

It works great on both IIS Express 8.0 and IIS 7.5 on Azure sites for URLs like /search/test (only ascii characters) - redirects to /?q=test . But for URLs with Unicode characters ( /search/ or /search/%D1%82%D0%B5%D1%81%D1%82 ) in IIS 7.5, Azure sites redirect to /?q=ร‘โ€šรยตร‘ร‘โ€š (or /?q=%C3%91%E2%80%9A%C3%90%C2%B5%C3%91%C2%81%C3%91%E2%80%9A ) instead of /?q=%D1%82%D0%B5%D1%81%D1%82 . It works correctly on IIS Express 8.0.

+4
source share
1 answer

You must use the internal function {UrlEncode{}} to correctly encode characters that are not allowed in the URL (for example, UTF-8 characters). So replace the url: url="?q={UrlEncode:{R:1}}" .

+7
source

All Articles