重写 URL iis 7 - https://www.somewhere.com -> https://somewhere.com
我正在尝试从 WWW 重定向我的网站 ->根。
http://www.example.com -> http://example.com https://www.example.com -> https://example.com
我使用了以下重写规则:
<rule name="CanonicalHostNameHttp" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
这工作正常:
失败:
- 我输入https://www.example.com
- 它永远不会重定向到https://example.com
- 结果它给了我一个证书错误(因为我的证书是为了example.com 不是 www.example.com)
我错过了什么???
I'm trying to redirect my site from WWW -> root.
http://www.example.com -> http://example.com
https://www.example.com -> https://example.com
i've used the following rewrite rules:
<rule name="CanonicalHostNameHttp" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
This works fine:
- I enter http://www.example.com, it redirects to http://example.com
- http://example.com then redirects to https://example.com
This fails:
- I enter https://www.example.com
- It never redirects to https://example.com
- And as a result it gives me a certificate error (because my certificate is for example.com not www.example.com)
What am I missing???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为 www.example.com 购买一个便宜的证书怎么样,正如这里提到的... 无效的安全性证书和域名
...然后设置一个规则来重定向 https://www.example.com -> https://example.com?
我现在也有类似的问题。问题是我无法安装第二个证书,因为 Amazon EC2 限制每个实例只能使用一个公共 IP 地址,并且一个 IP 地址只能绑定到一个证书。我能想到的唯一选择是更改非规范化域的 DNS 以指向另一台服务器,在那里安装第二个证书,然后将其重定向到我的 EC2 实例。
How about buying a cheap cert for www.example.com as mentioned here... invalid security certificate and domain names
...and then set up a rule to redirect https://www.example.com -> https://example.com?
I have a similar problem at the moment. The problem is I can't install a second cert because Amazon EC2 limits you to a single public IP address per instance, and an IP address can only be bound to one cert. The only option I can think of is to change the DNS of my non-canonicalised domain to point at another server, install the second cert there, and then get that to redirect to my EC2 instance.