2016-12-26 88 views
2

我想我的外部網站重定向到HTTPS我有以下web.config中規則:URL重寫web.config中與位置HTTPS

<location path="." inheritInChildApplications="false"> 
    <system.webServer> 
    <rewrite> 
     <rules> 

     <rule name="Redirect to https" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="off" `enter code here`ignoreCase="true" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" 
        redirectType="Permanent" appendQueryString="false" /> 
     </rule> 
    </rules> 
    </rewrite> 
    </system.webServer> 
</location> 

這個問題是因爲我有幾個服務託管在我的服務器是兒童,我不希望他們也重定向,我只是想重定向網站而不是服務。

回答

0

執行此操作的一種方法是默認重定向到除指定文件夾列表之外的HTTPS。在下面的示例中,重定向排除文件夾/service1//service2/。其他一切都轉到HTTPS。

<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="Redirect to https" stopProcessing="true"> 
       <match url=".*" /> 
       <conditions> 
        <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
        <!-- avoid redirection for the following paths --> 
        <add input="{PATH_INFO}" pattern="^/service1/" ignoreCase="true" negate="true" /> 
        <add input="{PATH_INFO}" pattern="^/service2/" ignoreCase="true" negate="true" /> 
       </conditions> 
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webServer>