C# 使用IIS将所有URL重定向到HTTPS/WWW版本
我有一个网站,刚刚购买了SSL。我希望所有URL重定向到它们的HTTPS/WWW版本。例如:C# 使用IIS将所有URL重定向到HTTPS/WWW版本,c#,asp.net,iis,web-config,C#,Asp.net,Iis,Web Config,我有一个网站,刚刚购买了SSL。我希望所有URL重定向到它们的HTTPS/WWW版本。例如: 1. http://mywebsite.com -> https://www.mywebsite.com 2. https://mywebsite.com -> https://www.mywebsite.com 3. http://www.mywebsite.com -> https://www.mywebsite.com 4. https://
1. http://mywebsite.com -> https://www.mywebsite.com
2. https://mywebsite.com -> https://www.mywebsite.com
3. http://www.mywebsite.com -> https://www.mywebsite.com
4. https://www.mywebsite.com -> [No redirect needed]
我已经尝试了一些解决方案:从标记为答案的方法。但对于案例2,几乎所有答案都返回“未找到。HTTP错误404
”,即https://mywebsite.com
未重定向到https://www.mywebsite.com
但返回了404
已经尝试过的解决方案:
一,
二,
似乎有些人也有这个问题。但是我找不到正确的解决方案。问题出在IIS的
站点绑定部分。没有https://mywebsite.com
。我添加了这个记录,问题中的解决方案成功了。有关此功能的更多信息,请访问
<rule name="Redirect top domains with non-www to www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^([^\.]+)\.([^\.]+)$" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" />
<serverVariables>
<set name="Redirect" value="false" />
</serverVariables>
</rule>
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>