2015-12-15 148 views
5

我有一些网站example.org,我保留子网站example.com/project1example.com/project2等等。我只需要在一些子网站上重定向HTTP→HTTPS,但不希望手动将其写入代码文件中。IIS URL重写:HTTP到HTTPS

所以我发现他URL-Rewrite2模块和规则:

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

它工作在最有一个问题:它重定向从http://example.com/project1https://example.com/,因此它失去的子网站的URL部分,任何ARGS。

这是如何解决的?

UPD:使用此规则

<rule name="Redirect to HTTPS" stopProcessing="true"> 
         <match url="(.*)" /> 
         <conditions> 
          <add input="{HTTPS}" pattern="^OFF$" /> 
         </conditions> 
         <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" /> 
</rule> 

子网站重定向通常除了参数被复制。 http://example.com/project1?page=2变成https://example.com/project1?page=2&page=2。我做错了什么?

回答

3

使用此规则完成:

<system.webServer> 
    <rewrite> 
      <rules> 
       <rule name="Redirect to HTTPS" stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions> 
         <add input="{HTTPS}" pattern="^OFF$" /> 
        </conditions> 
        <action type="Redirect" url="https://{HTTP_HOST}{UNENCODED_URL}" appendQueryString="false" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 

工程子网站上不错。

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

添加到system.webserver部分