2016-11-06 45 views
0

工作,我有網站有多個域名,我希望他們有不同的robots.txt 我有規則這使依賴於域名請求時,它會返回不同的機器人。這是工作測試版插槽,但在部署到生產插槽後無法使用。IIS重寫規則未在Azure中生產

<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> 

如果我改變動作類型重定向似乎工作,因爲網頁瀏覽器重定向,並在堅持了許多重定向(這是有意義的。)

回答

2

由於url-rewrite-module-configuration-reference提到,服務器變量REQUEST_URI可用於訪問整個請求的URL路徑,包括查詢字符串。假設robots.txt的URL爲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> 

通過上面的規則,我可以重寫我的網址,並得到以下結果:

改變從重寫規則動作類型重定向,我能得到以下結果:

+0

完蛋了:)我是,對於幾天掙扎,但這一如既往愚蠢的簡單的事情 –