Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7.5 URL Rewrite encoding

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.

like image 454
bacr Avatar asked Jan 23 '13 09:01

bacr


People also ask

How do I fix the URL Rewrite module in IIS?

IIS Rewrite Module ProblemUninstall the Rewrite Module from Windows Features. Go to the Web Platform Installer. Pick Url Rewrite from Products | Server section and install. Restart IIS.

What is rewrite URL in IIS?

About the URL Rewrite module The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find.


1 Answers

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}}".

like image 174
Marco Miltenburg Avatar answered Sep 24 '22 02:09

Marco Miltenburg