【问题标题】:Return 410 Error Based on Part of Query String in ASP.NET MVC基于 ASP.NET MVC 中的部分查询字符串返回 410 错误
【发布时间】:2017-07-09 03:44:34
【问题描述】:

寻找一种我们可以在 ASP.NET MVC-5 IIS-8 站点中使用的方法,以根据查询字符串中包含的短语列表返回 410 错误响应(已消失)。

为什么?我们每天都会收到数百次来自知名机器人(例如 Google、Bing、Yahoo)的垃圾点击,这些点击是我们网站上从未有过的名称荒谬的页面。我在想,对于这些页面中的大多数,我可以测试给定的关键短语是否存在,如果存在,则返回 410。我想返回 410 以告诉机器人他们可以永久删除他们的列表,从而提供逐步改善的 SEO 环境。

以下是我们收到的一些 URL 示例,其中包含我要测试的关键短语。

https://www.example.com:443/apple-touch-icon-precomposed.png

http://ww.w.example.com:80/zdjqhhmtkatt.html

我知道 .htaccess 在其他编程环境中非常可行,所以我希望 ASP.MVC 也有一个优雅的解决方案。

【问题讨论】:

    标签: asp.net-mvc-5 query-string iis-8 http-status-code-410


    【解决方案1】:

    您可以使用URL rewrite 模块来做到这一点。您的 web.config 中的规则应该是这样的:

    <rewrite>
        <rules>
            <rule name="410response" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{REQUEST_URI}" pattern="apple-touch" />
                    <add input="{REQUEST_URI}" pattern="zdjqhhmtkatt" />
                </conditions>
                <action type="CustomResponse" statusCode="410" statusReason="System unavailable" statusDescription="Gone. The requested resource is no longer available." />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      • 2018-10-19
      • 2020-11-06
      • 1970-01-01
      相关资源
      最近更新 更多