IIS 7.5 URL Rewrite encoding

azure-web-app-service, iis-7.5, url-rewriting

Solution

You should use the internal `{UrlEncode:{}}` function to properly encode the characters that are invalid in the URL (e.g. UTF-8 characters). So replace the URL part with: `url="?q={UrlEncode:{R:1}}"`.

Problem

I have 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 fine both on IIS Express 8.0 and IIS 7.5 on Azure Websites 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`) on IIS 7.5 on Azure Websites redirects 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.

Original source