如何重定向“https://www.host.com” > “https://host.com” > “https://host..net” (仅适用于 host.com 和 host.net 的证书)
我一直在努力让这个重定向发挥作用。
主要网站是 host.net
我希望 www.host.com
和 host.com
重定向到 host.net< /code> (位于另一台服务器外部的站点)
我有 host.com
和 host.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
场景
你要求
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。www.host.com
连接,该连接会重定向到https://www.host.net
。注释
Assumptions
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 tohttps://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 tohttps://host.net
, which is again ok.Solutions
https://www.host.com
https://host.com
andhttpd://www.host.com
.www.host.com
on port 80, which redirects tohttps://www.host.net
.Notes