如何重定向“https://www.host.com” > “https://host.com” > “https://host..net” (仅适用于 host.com 和 host.net 的证书)

发布于 2025-01-09 07:03:14 字数 1150 浏览 1 评论 0原文

我一直在努力让这个重定向发挥作用。

主要网站是 host.net

我希望 www.host.comhost.com 重定向到 host.net< /code> (位于另一台服务器外部的站点)

我有 host.comhost.net 的有效证书,但没有 www.host.com 的证书code>

我已经尝试过此设置,但客户端提供了证书。错误。 我尝试了多种组合,有时我可以使用其中一种,但不能同时使用两种重定向。

FROM .conf 文件示例:

<VirtualHost *:443> 
   ..
   LogLevel alert rewrite:trace8
   RewriteEngine On
    
   RewriteCond %{HTTP_HOST} www.host.com [NC]
   RewriteRule ^/$ https://host.com [R=301] 
    
   RewriteCond %{HTTP_HOST} host.com [NC]
   RewriteRule ^/$ https://host.net [R=301,L]

日志:

  init rewrite engine with requested uri /
  applying pattern '^/$' to uri '/'
  RewriteCond: input='host.com' pattern='www.host.com' [NC] => not-matched
  applying pattern '^/$' to uri '/'
  RewriteCond: input='host.com' pattern='host.com' [NC] => matched
  rewrite '/' -> 'https://host.net'
  explicitly forcing redirect with https://host.net
  escaping https://host.net for redirect
  redirect to https://host.net [REDIRECT/302]

I've been struggleing to get this redirect to work.

The main website is host.net

And I want www.host.com and host.com to redirect to host.net (site located external on antother server)

I have valid certificates for host.com and host.net but not for www.host.com

I've tried with this setup but the client gives a cert. error.
I've tried many combinations and sometimes I get one or the other to work, but not both redirects.

FROM .conf file example:

<VirtualHost *:443> 
   ..
   LogLevel alert rewrite:trace8
   RewriteEngine On
    
   RewriteCond %{HTTP_HOST} www.host.com [NC]
   RewriteRule ^/$ https://host.com [R=301] 
    
   RewriteCond %{HTTP_HOST} host.com [NC]
   RewriteRule ^/$ https://host.net [R=301,L]

LOG:

  init rewrite engine with requested uri /
  applying pattern '^/
 to uri '/'
  RewriteCond: input='host.com' pattern='www.host.com' [NC] => not-matched
  applying pattern '^/
 to uri '/'
  RewriteCond: input='host.com' pattern='host.com' [NC] => matched
  rewrite '/' -> 'https://host.net'
  explicitly forcing redirect with https://host.net
  escaping https://host.net for redirect
  redirect to https://host.net [REDIRECT/302]

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

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

发布评论

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

评论(1

情绪操控生活 2025-01-16 07:03:14

假设

  • 您拥有 host.com 和 host.net 的有效证书,
  • 而不是 www.host.com (就像你说的)

场景

  • 你要求https://host.com:你有一个有效的证书,所以它可以协商,并且输入您的 VH。这会重定向到 https://host.net 进行回答。这有一个有效的证书,所以你没问题。

  • 您要求https://www.host.com:您没有有效的证书,因此它会在协商时抱怨。协商发生在 apache 考虑 VH 之前。一旦您接受警告,它就会进入您的 VH,它将您发送至 https://host.net,这又没问题。

解决方案

  • https://www.host.com添加证书
  • ,获取涵盖https://host.com和<代码>httpd://www.host.com。
  • 仅接受端口 80 上的 www.host.com 连接,该连接会重定向到 https://www.host.net

注释

  • 您的日志显示您的配置良好,它符合您的预期。

Assumptions

  • you have a valid certificate for host.com and host.net
  • not for www.host.com (like you said)

Scenarios

  • you ask for https://host.com: you have a valid certificate, so it negotiates ok, and enters your VH. This answers with a redirect to https://host.net. This has a valid certificate, so you are ok.

  • you ask for https://www.host.com: you do not have a valid certificate, so it complains on negotiation. The negotiation happens before apache considers VH. Once you accept the warning, it enters your VH, which sends you to https://host.net, which is again ok.

Solutions

  • add a certificate for https://www.host.com
  • get a certificate to cover both https://host.com and httpd://www.host.com.
  • only accept connections for www.host.com on port 80, which redirects to https://www.host.net.

Notes

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