简体   繁体   中英

IIS Redirect Regex doesn't work with a space - %20 in URL

So I have one simple problem but somehow doesnt seem to work. I have one URL http://www.domain.com/%20#axzz2ZX4J0KAS which I want to redirect to http://www.domain.com/page-name.htm . I have tried so many combinations in IIS URL Rewrite/web.config and they all seem to work inside test pattern dialog but none works in browsers.

1.

<rule name="Redirect%20InHomePage" enabled="true" stopProcessing="true">
    <match url="^(.+)domain\.com/(\s|%20)(.+)" ignoreCase="true" />
    <action type="Redirect" url="http://www.domain.com/page-name.htm" />
</rule>

2.

   <match url="(.+)/%20(.+)" ignoreCase="true" />

3.

    <match url="(.+)domain.com/ (.+)" ignoreCase="true" />

4.

   <match url="(.+)domain.com/(\s|%20)(.+)" ignoreCase="true" />

As you can see I tried all of above patterns, they all work fine in Test Pattern dialog but when i browse URL, it always converts %20 to space and rule doesn't work for redirect.

Please help me for this simple yet unsolved problem, if anyone knows what am I missing.

I was having a similar issue and got it to work by typing spaces " " instead of %20 for my rules.

So here you may want to try [ ] for your space.

http://imgur.com/6sjWVjL

Don't include the domain name in your match url.

If you want to handle either having the tracking code or not in your url then you probably want to use something like this:

<rule name="RedirectSpaceInHomePage" stopProcessing="true">
  <match url="^\s(#\.*)?$" />
  <action type="Redirect" url="page-name.htm" />
</rule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM