带有异常的https重定向(错误)

时间:2015-12-15 20:32:57

标签: apache .htaccess https

我需要将所有 http 请求重定向到 https ,除了/ sports-scores,/ sport-scores /和sport-scores.html页面。

我已经待了两个小时。我的大脑是油炸的,从这个角度来说,我没有任何意义。

    <VirtualHost 127.0.0.1:80>

        DocumentRoot /var/www
        ServerName www.my-domain.com
        ServerAlias my-domain.com
        DirectoryIndex index.php index.html
        RewriteEngine on
        CustomLog /var/log/apache2/www.log combined
        ErrorLog /var/log/apache2/errors-www.log

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

</VirtualHost>

<VirtualHost 127.0.0.1:443>
        DocumentRoot /var/www
        ServerName www.my-domain.com
        ServerAlias my-domain.com
        DirectoryIndex index.php index.html
        SSLEngine on
        SSLCertificateFile   /home/user/gandi-ssl/www.crt
        SSLCertificateKeyFile /home/user/gandi-ssl/server.key
        SSLCertificateChainFile /home/user/gandi-ssl/www.crt
        CustomLog /var/log/apache2/www.log combined
        ErrorLog /var/log/apache2/errors-www.log

        RewriteEngine On
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

</VirtualHost>

1 个答案:

答案 0 :(得分:0)

  

我需要将所有http请求重定向到https,除了/ sports-scores,   / sport-scores /,和sport-scores.html页面。

您需要调整80虚拟主机配置并使用以下重写规则。

<VirtualHost 127.0.0.1:80>

    DocumentRoot /var/www
    ServerName www.my-domain.com
    ServerAlias my-domain.com
    DirectoryIndex index.php index.html
    CustomLog /var/log/apache2/www.log combined
    ErrorLog /var/log/apache2/errors-www.log

    RewriteEngine On
    RewriteCond %{HTTPS} !^on
    RewriteCond %{REQUEST_URI} !^/sports-scores
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 </VirtualHost>

 <VirtualHost 127.0.0.1:443>
    DocumentRoot /var/www
    ServerName www.my-domain.com
    ServerAlias my-domain.com
    DirectoryIndex index.php index.html
    SSLEngine on
    SSLCertificateFile   /home/user/gandi-ssl/www.crt
    SSLCertificateKeyFile /home/user/gandi-ssl/server.key
    SSLCertificateChainFile /home/user/gandi-ssl/www.crt
    CustomLog /var/log/apache2/www.log combined
    ErrorLog /var/log/apache2/errors-www.log

    RewriteEngine On
    RewriteCond %{HTTPS} ^on
    RewriteCond %{REQUEST_URI} ^/sports-scores
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 </VirtualHost>

让我知道这是如何解决的。