2017-10-19 363 views
1

目前,我的原则是:Web.config文件URL重定向到非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> 

的问题是在这里:

http://www.domainName.com/image.png错误地重定向到https://domainName.com 而不是https://domainName.com/image.png

https://www.domainName.com/image.png不会重定向到https://domainName.com/image.png

那么,将所有重定向到非www https URL的真正方法是什么?

回答

0

我做这件事是我的网站的方式如下:

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

我无法理解你在web配置环境中的意思! – user3196160

+2

这个答案不适用于IIS –

0

试试这个规则:

<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

正确的规则,这将满足您的所有需求是:

<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> 
相关问题