通配符SSL证书 - 将http重定向到https

时间:2011-11-29 22:02:45

标签: apache mod-rewrite virtualhost

我的所有网站都有一个HTTPS虚拟主机。我正在尝试将subsite2.server.co.uk从http重定向到https。

这是我的HTTPS虚拟主机(为简洁起见,我将其缩短了):

<VirtualHost _default_:443>   
    ServerName *.server.co.uk  
    ServerAdmin imran.azad@server.co.uk

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.subsite1.server.co.uk$ [NC]
    RewriteRule ^(.*)$ http://localhost:8080/VirtualHostBase/https
    /www.subsite1.co.uk:443/Plone/VirtualHostRoot/$1 [L,P]

    RewriteCond %{HTTP_HOST} ^subsite2.server.co.uk$ [NC]
    RewriteRule ^(.*)$ http://subsite2.server.co.uk/$1 [P]

这是我的HTTP虚拟主机:

<VirtualHost *:80>
    ServerName subsite2.server.co.uk
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    Alias /static-dir/ x:/.....
    <Directory x:/.....>
        Order deny,allow
        Allow from all
    </Directory>
    WSGIScriptAlias / x:/......
    <Directory  x:/......>
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost> 

我正在使用以下重写条件和规则来执行重定向:

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

然而,我遇到的问题是,似乎服务器处于重定向循环中。我怎样才能解决这个问题呢?

这是来自firefox的错误:

The page isn't redirecting properly

1 个答案:

答案 0 :(得分:1)

Mine正在使用类似的东西,我的猜测是,尝试使用你的正则表达式匹配而不是REQUEST_URI

RewriteEngine On
RewriteCond %{HTTP_HOST} =myhost.com
RewriteCond %{SERVER_PORT} !443
RewriteRule /(.*) https://%{SERVER_NAME}/$1 [R,L]