Search code examples
asp.neturl-rewritingiis-7.5httpmodule

IIS URL Re-write module with foreign text


We use IIS URL Re-write module, like this

<rule name="RewriteSearch" stopProcessing="true">
<match url="^Search/([_0-9a-z+-]+)" />
<action type="Rewrite" url="CommonPages/Search.aspx?term={R:1}" />
</rule>

http://www.tickettail.com/Search/NormalText123 Works fine

But...

http://www.tickettail.com/Search/ราคัดมาใ

(This is Thai) Will not. How can I modify the match to allow foreign text?

Thanks


Solution

  • The regular expression to which you are matching only accepts the characters _, 0 to 9, a to z, + and -. In order to accept all characters you have to modify the regular expression to e.g. (.+) (this accepts any character and requires at least one character.

    Second, in order for any character to be properly passed to the search page you have to URL encode the term by using the built in {UrlEncode:{}} function. Also make sure you page can handle and output UTF-8.

    The following rules works:

    <rule name="RewriteSearch" stopProcessing="true">
        <match url="^Search/(.+)" />
        <action type="Rewrite" url="CommonPages/Search.aspx?term={UrlEncode:{R:1}}" />
    </rule>