简体   繁体   English

HTTPS www在web.config中重定向

[英]HTTPS www redirects in web.config

I have the following in my web.config to force https; 我的web.config中有以下内容强制使用https;

<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

But I want to force the www. 但是我想强制www。 as well so that all of these would go to the https://www version. 以及所有这些都将转到https:// www版本。 What I need to achieve: 我需要实现的目标:

http://www.domain.tld/whatever
http://(no-www)domain.tld/whatever
https://(no-www)domain.tld/whatever

Thank you. 谢谢。

This rule will do the following: 该规则将执行以下操作:

  • Redirect to HTTPS 重定向到HTTPS
  • Force www 强制www

<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^www." negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

All that you need is to change www.example.com with your domain name 您所需www.example.com用您的域名更改www.example.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM