重写 URL iis 7 - https://www.somewhere.com -> https://somewhere.com

发布于 2025-01-03 23:22:25 字数 1720 浏览 4 评论 0原文

我正在尝试从 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:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唐婉 2025-01-10 23:22:25

为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文