如何将HTTPS重定向到HTTP?

时间:2008-08-12 00:36:32

标签: apache ssl redirect https

如何将HTTPS重定向到HTTP?也就是说,与每个人所教的(看似)相反。

我在HTTPS上有一台服务器,我已经为其支付了SSL认证和镜像,我没有并且只是为了紧急情况而保留,所以它不值得获得认证。

在我客户端的桌面上,我有一些指向http://production_serverhttps://production_server的快捷方式(两者都有效)。但是,我知道如果我的生产服务器出现故障,那么DNS转发就会启动,那些在其快捷方式上有“https”的客户端将会盯着https://mirror_server(这不起作用)和一个胖胖的Internet Explorer 7红色屏幕让我的公司感到不安。

不幸的是,我不能只在客户端级别进行切换。这些用户非常不懂计算机:并且非常有可能因为看到HTTPS“不安全”错误而感到恐惧(特别是现在Firefox 3和Internet Explorer 7处理它的方式:完全停止,有点谢天谢地,但没有帮助我这里大声笑)。

对于very easy来说,to find Apache solutions http->https redirection,但对于我的生活,我不能做相反的事情。

想法?

11 个答案:

答案 0 :(得分:124)

这尚未经过测试,但我认为这应该可以使用mod_rewrite

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

答案 1 :(得分:68)

请记住,一旦收到HTTP请求,Rewrite引擎才会启动 - 这意味着您仍然需要证书,以便客户端设置连接以发送请求!

但是,如果备份计算机看起来具有相同的主机名(就客户端而言),那么就没有理由不能使用与主生产计算机相同的证书。

答案 2 :(得分:10)

根据ejunker的回答,这是适用于我的解决方案,不是在单个服务器上,而是在环境

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

答案 3 :(得分:8)

对于那些使用.conf文件的人。

<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>

答案 4 :(得分:6)

如果以上解决方案都不适合您(他们不适合我),这就是我服务器上的工作原理:

RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]

答案 5 :(得分:4)

当我使用cloudflare时,以上所有内容都不起作用,这个对我有用:

RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这个肯定在没有代理的情况下工作:

RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

答案 6 :(得分:2)

最好尽可能避免使用mod_rewrite。

在你的情况下,我会用这个替换Rewrite:

    <If "%{HTTPS} == 'on'" >
            Redirect permanent / http://production_server/
    </If>

根据blog here<If>指令仅适用于Apache 2.4+。

答案 7 :(得分:0)

在Wordpress网站上我的答案都没有,但是后续作品(它与其他答案类似,但有一些变化)

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

答案 8 :(得分:0)

这对我有用。

<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。

答案 9 :(得分:0)

如果您正在寻找可以将特定 url/s 重定向到 http 的答案,请更新您的 htaccess,如下所示

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/(home/panel/videos|user/profile) [NC] # Multiple urls
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /(home/panel/videos|user/profile) [NC] # Multiple urls
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

它对我有用:)

答案 10 :(得分:-7)

据我所知,简单的元刷新也可以在不引起错误的情况下运行:

<meta http-equiv="refresh" content="0;URL='http://www.yourdomain.com/path'">