IIS重写规则在Azure生产中不起作用

时间:2016-11-06 23:54:15

标签: azure url-rewriting azure-web-sites

我的网站有多个域名,我希望他们有不同的robots.txt 我有这个规则所以取决于域请求它将返回不同的机器人。这是在beta插槽中工作,但在部署到生产插槽后它无法正常工作。

<rule name="robots" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_URI}" pattern="^robots.txt" />
          </conditions>
          <action type="Rewrite" url="https://{HTTP_HOST}/{HTTP_HOST}.robots.txt" />
        </rule>

如果我正在更改动作类型以重定向它似乎有效,因为webbrowser重定向并且与许多重定向相关(这是有意义的。)

1 个答案:

答案 0 :(得分:2)

url-rewrite-module-configuration-reference所述,服务器变量REQUEST_URI可用于访问整个请求的URL路径,包括查询字符串。假设robots.txt的网址为https://<your-hostname-and-port>/robots.txt,那么您将通过/robots.txt获取字符串REQUEST_URI作为输入。

<rewrite>
  <rules>
    <rule name="robots" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="(.*)" ignoreCase="true"/>
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_URI}" pattern="^/robots.txt" />
      </conditions>
      <action type="Rewrite" url="{HTTP_HOST}.robots.txt"/>
    </rule>
  </rules>
</rewrite>

根据上述规则,我可以重写我的网址并获得以下结果:

将规则操作的类型从Rewrite更改为Redirect,我可以得到以下结果: