简体   繁体   English

IIS重定向正则表达式不适用于空格 - URL中的%20

[英]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 . 我有一个网址http://www.domain.com/%20#axzz2ZX4J0KAS ,我想重定向到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. 我在IIS URL Rewrite / web.config中尝试了很多组合,它们似乎都在测试模式对话框中工作,但在浏览器中都不起作用。

1. 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. 2。

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

3. 3。

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

4. 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. 正如您所看到的,我尝试了以上所有模式,它们在“测试模式”对话框中都能正常工作,但是当我浏览URL时,它总是将%20转换为空格,而规则不适用于重定向。

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. 我有一个类似的问题,并通过键入空格“”代替%20来实现我的规则。

So here you may want to try [ ] for your space. 所以在这里你可能想尝试[]为你的空间。

http://imgur.com/6sjWVjL 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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