【问题标题】:ASP.NET Web.config URL Rewrite RegexASP.NET Web.config URL 重写正则表达式
【发布时间】:2018-07-11 13:52:56
【问题描述】:

我正在尝试清理一些返回 404 而不是 200 的请求。

例如有人有这样的链接到我的网站:

http://example.com/?publisher=123456

我正在尝试添加一个重写规则来处理这种情况:

    <rule name="Redirect publisher" stopProcessing="true">
      <match url="(.*)\/\?publisher=(.*)$" negate="false" />
      <conditions logicalGrouping="MatchAny" trackAllCaptures="false"></conditions>
      <action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="The requested URL was not found." />
    </rule>

我关注了Microsoft instructions,但是,即使my test 显示上述正则表达式应该可以工作,但什么也没有发生。我尝试做一个更常见的重定向,像这样:

<action type="Redirect" url="https://{HTTP_HOST}" redirectType="Permanent" />

然而,又没有任何反应。好像我的正则表达式不好?

【问题讨论】:

    标签: asp.net regex url-rewriting


    【解决方案1】:

    我终于弄明白了:

        <rule name="Redirect publisher" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{QUERY_STRING}" pattern="publisher" negate="false" />
          </conditions>
          <action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="The requested URL was not found." />
        </rule>
    

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      相关资源
      最近更新 更多