如何将HTTPS重定向到HTTP?也就是说,每个人(似乎)都在教相反的东西。
我在HTTPS上有一台服务器,为此我支付了SSL认证,还有一台我没有为其镜像的镜像,并且只为紧急情况而保留,因此它不值得获得证书。
在我的客户的桌面上,我有一些指向http://production_server和https://production_server的快捷方式(均可用)。但是,我知道,如果我的生产服务器出现故障,则DNS转发开始,那些快捷方式上带有" https"的客户端将盯着https://mirror_server(不起作用),并显示一个很大的Internet Explorer 7红色屏幕让我公司感到不安。
不幸的是,我不能仅仅在客户端级别上进行切换。这些用户非常懂计算机:并且很可能不愿意看到HTTPS"不安全"错误(尤其是现今Firefox 3和Internet Explorer 7的处理方式:FULL STOP,谢天谢地,但在这里没有帮助我)。
找到用于http-> https重定向的Apache解决方案非常容易,但是在我的一生中,我不能相反。
有想法吗?
这尚未测试,但我认为应该使用mod_rewrite
1 2 3
| RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} |
请记住,重写引擎仅在收到HTTP请求后才启动-这意味着您仍将需要证书,以便客户端建立连接以将请求发送过来!
但是,如果备份计算机似乎具有相同的主机名(就客户端而言),那么就没有理由不能使用与主生产计算机相同的证书。
根据ejunker的回答,这是适用于我的解决方案,而不是在单个服务器上,而是在云环境中
1 2 3 4
| Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
对于那些使用.conf文件的文件。
1 2 3 4 5 6 7 8 9 10 11 12
| <VirtualHost *:443>
ServerName domain.com
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/domain.crt
SSLCertificateKeyFile /etc/apache2/ssl/domain.key
SSLCACertificateFile /etc/apache2/ssl/domain.crt
</VirtualHost> |
如果以上解决方案都不对您有用(对我而言不起作用),那么这是在我的服务器上起作用的:
1 2
| RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301] |
当我使用cloudflare时,以上所有方法均不起作用,这对我有用:
1 2
| RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
并且这个绝对可以在没有代理的情况下工作:
1 2
| RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
最好避免使用mod_rewrite。
在您的情况下,我将用以下内容替换Rewrite:
1 2 3
| <If"%{HTTPS} == 'on'">
Redirect permanent / http://production_server/
</If> |
根据此博客,指令仅在Apache 2.4+中可用。
这对我有用。
1 2 3 4 5 6 7 8 9 10
| <VirtualHost *:443>
ServerName www.example.com
# ... SSL configuration goes here
Redirect"https://www.example.com/""http://www.example.com/"
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
# ...
</VirtualHost> |
确保同时监听端口80和443。
在Wordpress网站上,没有一个答案对我有用,但随后的工作(与其他答案相似,但有少许变化)
1 2 3
| RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
据我所知,简单的元刷新也可以正常工作而不会引起错误:
1
| <meta http-equiv="refresh" content="0;URL='http://www.yourdomain.com/path'"> |