0

寻找一种我们可以在 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 也有一个优雅的解决方案。

4

1 回答 1

0

您可以使用URL 重写模块来做到这一点。您的 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>
于 2017-07-09T12:05:12.437 回答