2015-12-15 12 views
5

Ich habe einige Website example.org, auf denen ich Unterwebsites wie example.com/project1 und example.com/project2 und so weiter. Ich brauche einfach HTTP→HTTPS Redirect auf einigen Unterwebsites, aber möchte nicht in Codefiles manuell schreiben.IIS URL-Rewrite: HTTP zu HTTPS

So fand ich URL-Rewrite2 Modul und Regel für ihn:

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

Es höchstens mit einem Problem arbeitet: es leitet http://example.com/project1-https://example.com/, so dass es Subsite URL Teil und alle args verloren.

Wie kann das behoben werden?

UPD: verwendet diese Regel

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

Subsite normalerweise leitet, außer dass Argumente dupliziert. http://example.com/project1?page=2 wird zu https://example.com/project1?page=2&page=2. Was mache ich falsch?

Antwort

3

mit dieser Regel Done:

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

Arbeiten auf subsites gut.

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> 

hinzufügen, dass an den system.webServer Abschnitt