在apache中将https://server.com重定向到https://www.server.com

发布于 2025-01-07 15:30:15 字数 384 浏览 1 评论 0原文

我正在尝试在 apache 中为模式 URL 编写一个重定向:

https://server.comhttps://www.server.com

但没有取得太大成功

重定向原因:我的 SSL 证书位于 www.server.com 上,因此我希望用户访问正确的站点(并看到安全图标)。

问题:问题是,当我尝试打开 https://server.com 时,浏览器会给出不正确的证书错误,并且我的 RewriteRule 不会被执行,直到我忽略证书不正确的问题。

在这种情况下我该如何重定向?

I am trying to write a redirect in apache for URL of pattern:

https://server.com to https://www.server.com

without much success

Reason for rediect: My SSL certificate is on www.server.com, so I want the users to go on the correct site (and see secure icon).

Problem: The problem is that when I try to open https://server.com the browser gives me incorrect certificate error and none of my RewriteRule gets executed till I ignore the incorrect certificate problem.

How do I redirect in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

书间行客 2025-01-14 15:30:15

您无法仅凭一张证书来完成此操作。原因是 Web 服务器需要在进行重定向之前进行 ssl 握手,因此您总是会遇到证书无效的问题。

您实际上只有一个选择来执行此操作 - 使用证书和重定向来覆盖 www 和无 www。这可以通过多种方式完成,要么获取具有多个域名的证书(称为 SAN 证书),要么获取两个证书,一个用于 www,另一个不包含 www。然而,在第二种情况下,您将需要两个具有不同 IP 的 Web 服务器来完成您的任务。

另一种方法,即我自己使用的方法,就是不用担心。当需要 SSL 连接时,指示用户转到常规 http 网站并自行进行重定向。这就是 amazon.com 实际所做的。他们希望你浏览 http,只有当你买东西时他们才会将你重定向到 SSL。他们的证书也仅对 www 有效,只需访问 https://amazon.com,您就会看到他们的证书在没有 www 的情况下无效

You can't do this with one certificate. The reason is that the web server needs to do the ssl handshake before it does the redirect, so you'll always have the problem with invalid certificate.

You really have only one option to do this - cover both, www and no www with a certificate and redirect. This can be done several ways, either get a certificate with multiple domain names called a SAN certificate, or get two certificates, one for www and one without. However, in the second case, you would need two web servers with different ip's to accomplish your task.

An alternate approach, one that use myself, is not to worry about it. Instruct users to go to regular http website and do the redirection yourself when SSL Cconnection is needed. This is what amazon.com does actually. They want you to browse http and they redirect you to SSL only when you buy something. Their certificate is also only valid for www, just go to https://amazon.com and you'll see their certificate is invalid without www

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