【问题标题】:IIS rewrite module - Encoded space at end of URL, looking for a rewrite rule to redirect the pageIIS 重写模块 - URL 末尾的编码空间,寻找重写规则来重定向页面
【发布时间】:2015-01-17 06:16:29
【问题描述】:

我有一个讨厌的小问题。我正在使用带有重写模块的 MVC 3。从另一个链接到 mysite 的网站有一个指向我的网站的链接:

hxxp:www.mysite.com/%20

即其他网站将 %20(编码的空格字符)广告到其网址的末尾。

现在我需要将此链接重定向到主站点,如下所示:

hxxp://www.mysite.com/

否则它会给出 404 not found 错误。

现在我尝试了不同的重写规则,但似乎没有任何东西可以重定向网站,例如

<rule name="redirect space" stopProcessing="true">
          <match url="^hxxp://www.mysite.com/%20" />
          <action type="Redirect" url="hxxp://www.mysite.com/" redirectType="Permanent" />
        </rule>

和许多其他组合,但似乎没有什么可以解决它,并且在每种情况下都会出现 404 错误。

【问题讨论】:

  • 相当肯定匹配规则是正则表达式,这意味着您的示例无效。这行得通吗:^hxxp:\/\/www\.mysite\.com\/%20?
  • &lt;match url="^%20" /&gt;替换&lt;match url="^hxxp://www.mysite.com/%20" /&gt;
  • 两个都试过了:^hxxp:\/\/www\.mysite\.com\/%20 和 但还是不行。
  • 我认为重写引擎将 %20 视为空格,所以可以使用正则表达式作为空格?
  • &lt;match url="^ $" /&gt; 怎么样?

标签: c# regex asp.net-mvc-3 url-rewrite-module


【解决方案1】:

尝试为空格添加一些变体:编码一个,解码一个空格字符,如下所示:

<rule name="redirect space" stopProcessing="true">
  <match url="^hxxp://www.mysite.com/((%20)|\ |\s)+" />
  <action type="Redirect" url="hxxp://www.mysite.com/" redirectType="Permanent" />
</rule>

更多信息可以在这里找到:

如果这仍然不起作用,您必须编写自己的重写模块。你可以在这里看到更多细节:

Replace %20 in Url with - in C#.net web.config

【讨论】:

    猜你喜欢
    • 2012-05-27
    • 1970-01-01
    • 2011-04-21
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 2014-10-27
    相关资源
    最近更新 更多