【问题标题】:Configure IIS to use different robot.txt for https requests配置 IIS 以对 https 请求使用不同的 robots.txt
【发布时间】:2011-02-07 20:06:34
【问题描述】:

如何为 https 请求使用不同于 IIS 7 中用于 http 连接的 robots.txt?

谢谢。

【问题讨论】:

    标签: iis iis-7 robots.txt


    【解决方案1】:

    这里有几个选项,具体取决于您需要的自定义程度。最灵活的方法是编写一个处理程序并将其映射到机器人请求,并在内部处理。

    但是,对于大多数需求,请尝试 URL 重写模块 http://www.iis.net/download/urlrewrite

    在我的脑海中(又名概率不能 100% 起作用),它类似于:

    <rule name="https_robots">
      <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/robots-https.txt" />
    </rule>
    

    【讨论】:

    • 使用 Url Rewrite 将 whatever.com/robots.txt 重写为 whatever.com/robots-for-https.txt 或您需要的任何内容。给你一个例子,见编辑答案
    • 确实使用 URL 重写,您应该能够添加一个规则,如 Taylor 建议的,可以返回不同的文件(通过重定向,或者可能更容易重写到不同的文件,例如robotsSSL.txt),在该文件中设置一个 Disallow:/ 以便它阻止所有。
    【解决方案2】:

    遇到了完全相同的问题:

    我现在正在设置 https 版本,想看它并不急于调试它,同时防止谷歌抓取 https,但保持 http“一切照旧”。这是我在配置文件中使用的一段代码:

    <rule name="https_robots"  stopProcessing="true">
      <match url="^robots\.txt$" />
        <conditions>
          <add input="{HTTPS}" pattern="^OFF$" />
        </conditions>
       <action type="Rewrite" url="robots_https.txt" />
    </rule>
    

    几点说明:

    基本上,我创建了一个包含“禁止所有人”指令的文件“robots_https.txt”。

    我使用了重写,而不是重定向。我不确定蜘蛛是否会获得重定向。我真的很怀疑。使用 Rewrite 不会出错。

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      相关资源
      最近更新 更多