2017-10-19 45 views
1

umleiten Derzeit ist meine Regel:Web.config URL zu nicht-www + https

<rule name="SecureRedirect" stopProcessing="true"> 
    <match url="^(.*)$" /> 
    <conditions> 
    <add input="{HTTPS}" pattern="off" /> 
    <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" /> 
    </conditions> 
    <action type="Redirect" url="https://{C:2}" redirectType="Permanent" /> 
</rule> 

Das Problem dabei ist:

http://www.domainName.com/image.png Umleitungen falsch zu https://domainName.com statt https://domainName.com/image.png

und

https://www.domainName.com/image.png wird nicht immer aufumgeleitet

Also, was ist der wahre Weg, um alle auf nicht-www https URL umleiten?

Antwort

0

So wie ich auf meiner Seite hat es sich wie folgt:

ServerName www.example.com 
ServerAlias example.com 
Redirect/https://www.example.com/ 
+0

Ich kann nicht verstehen, was Sie damit in der Web-Config-Umgebung meinen! – user3196160

+2

Diese Antwort ist nicht für IIS –

0

diese Regel Versuchen:

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

Die richtige Regel, die alle Ihre Anforderungen passt ist:

<rule name="SecureRedirect" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAny"> 
     <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" /> 
     <add input="{HTTPS}" pattern="off" /> 
    </conditions> 
    <action type="Redirect" url="https://{C:2}/{R:1}" redirectType="Permanent" /> 
</rule>