2015-12-15 22 views
5

Ho qualche sito example.org, sul quale tengo siti secondari come example.com/project1 e example.com/project2 e così via. Ho bisogno di un semplice reindirizzamento HTTP→HTTPS solo su alcuni dei siti secondari, ma non voglio scriverlo nei file di codice manualmente.IIS URL-Riscrivi: HTTP a HTTPS

Così ho trovato URL-Rewrite2 modulo e la regola per lui:

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

Funziona al massimo con un problema: si reindirizza http://example.com/project1-https://example.com/, parte sottosito URL quindi è perso e gli eventuali argomenti.

Come può essere risolto?

UPD: usato questa regola

<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 reindirizza normalmente tranne che gli argomenti si duplicazione. http://example.com/project1?page=2 diventa https://example.com/project1?page=2&page=2. Cosa sto facendo di sbagliato?

risposta

3

fatto usando questa regola:

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

Funziona bene su siti secondari.

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> 

aggiungere che alla sezione system.webServer