非法入境8重定向URL从http到https [英] IIs 8 Redirect URL from http to https
问题描述
我刚才setuped SSL我dmain和主机。我想我的网站限制在 https://www.example.com
只有
I have just setuped ssl for my dmain and host. I want to limit my site to https://www.example.com
ONLY.
如果任何用户试图打开 http://example.com
, www.example.com
, example.com
或 https://example.com
他必须被重定向到 HTTPS: //www.example.com中
If the any user tried to open http://example.com
, www.example.com
, example.com
or https://example.com
he must be redirected to https://www.example.com
我也想任何一个重定向是只有域名和URL的其余部分保持不变,例如,如果用户打开 example.com/dir1/page1.aspx
他将被重定向到 https://www.example.com/dir1/page1.aspx
I want also any the redirection to be for the domain name only and rest of the URL remain as is for example if user opened example.com/dir1/page1.aspx
he will be redirected to https://www.example.com/dir1/page1.aspx
我想用IIS重写规则去做。
I want to do it using IIS rewrite rules.
推荐答案
我加入这个code到 web.confing
解决了这个问题的文件域。
I solved this problem by adding this code to web.confing
file on the root directory of the domain.
- 第一条规则,如果它的没有启动与
WWW
的URL匹配什么都
这是HTTP
或HTTPS
-
第二条规则的URL,如果它的开始匹配与
WWW
但不是HTTPS
- First rule matches the url if it isn't starting with
www
what ever it ishttp
orhttps
second rule matches the url if it is starting with
www
but it isn'thttps
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect from non www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Redirect from non https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
这篇关于非法入境8重定向URL从http到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!