Web.config文件URL重定向到非www + HTTPS
问题描述:
目前,我的原则是: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的真正方法是什么?
答
我做这件事是我的网站的方式如下:
ServerName www.example.com
ServerAlias example.com
Redirect/https://www.example.com/
答
试试这个规则:
<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>
答
正确的规则,这将满足您的所有需求是:
<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>
我无法理解你在web配置环境中的意思! – user3196160
这个答案不适用于IIS –