[英]redirect https:// to https://www in IIS 8
Suppose I have a site http://www.example.com which was 301 redirect from http://example.com to http://www.example.com . 假设我有一个网站http://www.example.com ,它是从http://example.com重定向到http://www.example.com的 301。
Now after Google's recent update about using SSL for better rankings, I decided to use SSL. 现在,在Google最近发布有关使用SSL获得更好排名的更新之后,我决定使用SSL。
I am using below code in web.config
to 301 redirect to https 我在
web.config
使用以下代码将301重定向到https
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
now its redirecting 301 all requests http://www.example.com and http://example.com to https://www.example.com 现在,它会将所有请求http://www.example.com和http://example.com重定向301到https://www.example.com
but it's not redirecting https://example.com to https://www.example.com 但不会将https://example.com重定向到https://www.example.com
I want to do this for only one canonical version as many SEO authority sites suggested. 我想仅针对许多SEO权威网站建议的规范版本执行此操作。
If I use Plesk builtin functionality to redirect all non www to www, then it does double redirect. 如果我使用Plesk内置功能将所有非www重定向到www,则它会进行两次重定向。
How can I do this, Please help 我该怎么办,请帮忙
Try a second rule to enforce the www, such as: 尝试使用第二条规则来实施www,例如:
<rule name="Enforce WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^https://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="https://www.{C:1}" redirectType="Permanent" />
</rule>
The condition you have on your rule will stop it firing for a https request such as https://example.com . 您的规则所具有的条件将阻止它针对诸如https://example.com之类的https请求触发。
Version #2 Try putting this before your other rule, the stopProcessing should stop it going circular. 版本#2尝试将此规则放在其他规则之前,stopProcessing应该阻止它循环运行。
<rule name="Enforce WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.com" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.