【问题标题】:htaccess 301 redirect https to https and http to httphtaccess 301 重定向 https 到 https 和 http 到 http
【发布时间】:2015-07-16 02:48:47
【问题描述】:

我看到很多关于 http 到 https 和 https 到 http 重定向的问题,但没有关于将所有流量(包括 http 和 https)重定向到新站点的问题。

这是我的 htaccess 文件的样子,但它不起作用。如何将 https 请求重定向到 https://www.mynewsite.com/ 并将 http 请求重定向到 http://www.mynewsite.com/ ?

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} ^on
RewriteRule ^(.*)$ https://www.mynewsite.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ http://www.mynewsite.com%{REQUEST_URI} [R=301,L]

【问题讨论】:

  • 附加到第二个条件的重写规则总是触发;第一个永远不会开火。 “https://www.oldsite.com”和“http://www.oldsite.com”总是 301 到“http://www.newsite.com/”而不是 https 站点
  • 如果你去掉这个.htaccess并输入https://example.com,它显示的内容和http://example.com一样吗?
  • 是的,它确实显示了相同的信息。

标签: .htaccess http redirect https


【解决方案1】:

这应该完成将 http 和 https 请求分别重定向到新站点。 HTTP 到 HTTP 和 HTTPS 到 HTTPS,只是从旧 URL 到新 URL:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^/?(.*) https://www.mynewsite.com/$1 [R=301,L] 
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) http://www.mynewsite.com/$1 [R=301,L] 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 2019-08-12
    • 1970-01-01
    • 2016-11-08
    • 2019-02-04
    • 2015-02-16
    • 2014-11-18
    相关资源
    最近更新 更多