2017-07-12 76 views
0

我有這樣的重寫規則中:IIS HTTP到HTTPS時,We​​b應用程序是網站

<rewrite> 
     <rules> 
    <rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true"> 
     <match url="*" negate="false" /> 
     <conditions logicalGrouping="MatchAny"> 
      <add input="{HTTPS}" pattern="off" /> 
     </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" /> 
    </rule> 
</rules> 
    </rewrite> 

我想rediret所有HTTP到HTTPS TRAFIC,但事情是我的web應用程序是不是在根文件夾,所以它是這樣的:

http:\\my-site.com\MyWebApp\some-parameters-here

和重定向後它去:

https:\\my-site.com\some-parameters-here

...而不是

https:\\my-site.com\MyWebApp\some-parameters-here

這怎麼重定向可以固定而不URL硬作弄那一部分?

回答

0

這對我的作品:

<rule name="HTTP to HTTPS redirect" enabled="false" stopProcessing="true"> 
<match url="(.*)" /> 
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTPS}" pattern="^OFF$" /> 
     <add input="{HTTP_HOST}" pattern="^((.+)?my-site\.com)$" /> 
</conditions> 
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" /> 

的關鍵是,替換:{R:1}。這是允許的,以保持完整的鏈接沒有HTTP_HOST

UPDATE 關於您的評論

您可以使用:

<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
    <add input="{HTTPS}" pattern="^OFF$" /> 
    </conditions> 
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" 
     redirectType="Permanent" /> 
    </rule> 
+0

肯定。您可以刪除該行。這部分我們的配置。我們有幾個沒有證書的網站。 – SouXin

+0

謝謝,這對我有用。 – ShP

相關問題