【问题标题】:Redirect from HTTPS to HTTPS of other website从 HTTPS 重定向到其他网站的 HTTPS
【发布时间】:2020-05-21 09:02:12
【问题描述】:

我已经阅读了一些其他问题,它们的内容几乎相同,但我无法复制相同的内容。

https://serverfault.com/questions/167395/redirect-https-to-another-https

Apache HTTPS to HTTPS Redirection

(我都试过了)

当用户点击或输入 https:// 版本时,我想将我的网站(https://website1.com)重定向到另一个网站(https://website2.com)。

到目前为止,我已经实现的是,当用户点击网站的http://website1.com 版本时,他们会被重定向到https://website2.com,但是当https://website1.com 它加载https://website1.com 时,不会发生重定向。

我使用的是 Apache HTTPD,下面是我的 httpd.conf 文件条目:

<VirtualHost *:80>    
    ServerName website1.com
    ServerAlias www.website1.com
    RewriteEngine On
    RewriteCond %{ENV:HTTPS} on
    RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
    RedirectPermanent / https://website2.com/
</VirtualHost>

【问题讨论】:

  • 我不记得 Apache 配置,但您显示的仅适用于端口 80,它仅适用于 http。
  • 我认为虚拟主机只负责引导流量。如果您能够提供帮助并且为此需要任何其他 sn-p,您可以告诉我。 :443 端口代码没有任何其他的服务器名称我已经检查过了。

标签: redirect https httpd.conf


【解决方案1】:

HTTP 似乎缺少 OR 条件。

以下代码应该可以工作,虽然我还没有测试过。

<VirtualHost *:80>    
   ServerName website1.com
   ServerAlias www.website1.com
   RewriteEngine On
   RewriteCond %{ENV:HTTPS} [OR]
   RewriteCond %{ENV:HTTP} on
   RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
   RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
   RedirectPermanent / https://website2.com/
</VirtualHost>

【讨论】:

  • 不。还是一样。
猜你喜欢
  • 2018-08-13
  • 2013-07-03
  • 1970-01-01
  • 2021-04-02
  • 1970-01-01
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
  • 2015-05-10
相关资源
最近更新 更多