2015-12-02 207 views
1

我有定義了以下入站和出站規則以使我的反向代理工作。IIS反向代理在特定路徑上應用出站規則

<rewrite> 
    <rules> 
     <rule name="Route the requests for backend app" stopProcessing="true"> 
      <match url="^foldera/folderb/(.*)" /> 
      <conditions> 
       <add input="{HTTP_HOST}" pattern="www.site1.com" /> 
      </conditions> 
      <action type="Rewrite" url="http://www.site2.com/{R:1}" /> 
      <serverVariables> 
       <set name="HTTP_ACCEPT_ENCODING" value="" /> 
      </serverVariables> 
     </rule> 
    </rules> 
    <outboundRules> 
     <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml" enabled="true" stopProcessing="false"> 
      <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" /> 
      <action type="Rewrite" value="/foldera/folderb/{R:1}" /> 
      <conditions> 
       <add input="{URL}" pattern="^/foldera/folderb/.*" /> 
      </conditions> 
     </rule> 
     <preConditions> 
      <preCondition name="ResponseIsHtml"> 
       <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
      </preCondition> 
     </preConditions> 
    </outboundRules> 
</rewrite> 

現在,該網站「http://www.site2.com/」是correclty加載「http://www.site1.com/foldera/folderb/」和出站規則是確保從站點2每一個資源被改寫爲http://www.site1.com/foldera/folderb/ {resourcefromsite1} 不幸的是,出站規則也被撞碎了我的網站的其餘部分。可能是因爲他試圖將每個本地資源重寫爲相同的「http://www.site1.com/foldera/folderb/」文件夾結構。 我怎樣才能讓出站規則只適用於採用http://www.site1.com/foldera

乾杯 通過路徑http://www.site1.com/foldera/folderb/和例如未加載所請求的資源/響應的Jeroen

回答

0

你是非常接近的解決方案。要解決此問題,您必須在preCondition內添加{URL}作爲輸入。您的重寫規則應該是這樣的最後:

<rewrite> 
    <rules> 
     <rule name="Route the requests for backend app" stopProcessing="true"> 
      <match url="^foldera/folderb/(.*)" /> 
      <conditions> 
       <add input="{HTTP_HOST}" pattern="www.site1.com" /> 
      </conditions> 
      <action type="Rewrite" url="http://www.site2.com/{R:1}" /> 
      <serverVariables> 
       <set name="HTTP_ACCEPT_ENCODING" value="" /> 
      </serverVariables> 
     </rule> 
    </rules> 
    <outboundRules> 
     <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml" enabled="true" stopProcessing="false"> 
      <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" /> 
      <action type="Rewrite" value="/foldera/folderb/{R:1}" /> 
      <!-- Removed condition from here --> 
     </rule> 
     <preConditions> 
      <preCondition name="ResponseIsHtml"> 
       <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
       <add input="{URL}" pattern="^/foldera/folderb/.*" /> <!-- Added your condition here --> 
      </preCondition> 
     </preConditions> 
    </outboundRules> 
</rewrite> 

這樣站規則將只適用於當響應HTML和電流URL得到指定的模式。