简体   繁体   English

http到http重定向Apache中的虚拟主机

[英]http to http redirect virtual host in apache

Hi im configuring a server in CentOS 6.5 with apache 2.4 and PHP 5.5 I install an SSL certificate and all go fine. 您好,我在CentOS 6.5中使用apache 2.4和PHP 5.5配置服务器时,我安装了SSL证书,一切正常。

in another server i did the http to https redirect on htaccess file. 在另一台服务器上,我在htaccess文件上执行了HTTP到https重定向。 i meke test with that in my new server and didnt work, here are my configuration: 我在新服务器上进行测试,但没有工作,这是我的配置:

My .htaccess: 我的.htaccess:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>

        RewriteEngine On

        # Redirect Trailing Slashes...
        RewriteRule ^(.*)/$ /$1 [L,R=301]

        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond   %{REQUEST_URI}  !/phpmyadmin/.*
        RewriteCond   %{REQUEST_URI}  !/phpMyAdmin/.*
        RewriteRule ^ index.php [L]
    </IfModule>

My virtual host file: 我的虚拟主机文件:

    NameVirtualHost *:80

    <VirtualHost *:80>
            ServerName subdomain.domain.com
            ServerAlias www.subdomain.domain.com
            DocumentRoot /var/www/laravel-project-namel/public

           <Directory /var/www/laravel-project-namel/public>
              <IfModule mod_rewrite.c>
              Options -MultiViews
              RewriteEngine On

                RewriteCond %{HTTP_HOST} ^www\.(.*)
                RewriteRule ^.*$ https://%1/$1 [R=301,L]


              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteRule ^ index.php [L]


           </IfModule>
        </Directory>
    </VirtualHost>

    NameVirtualHost *:443

    <VirtualHost *:443>
            SSLEngine on
            SSLProtocol all -SSLv2
            SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
            SSLCertificateFile /etc/pki/tls/certs/cert-valido_clientes_databyte_cl.crt
            SSLCertificateKeyFile /etc/pki/tls/certs/cert-valido-private.key
            SSLCertificateChainFile /etc/pki/tls/certs/cert-valido_clientes_databyte_cl.pem
            ServerName subdomain.domain.com
            ServerAlias www.subdomain.domain.com
            DocumentRoot /var/www/laravel-project-namel/public

           <Directory /var/www/laravel-project-namel/public>
              <IfModule mod_rewrite.c>
              Options -MultiViews
              RewriteEngine On
              RewriteCond %{REQUEST_FILENAME} !-f
             RewriteRule ^ index.php [L]
           </IfModule>
        </Directory>
    </VirtualHost>

i replace the domain and the folder to generic names, but all other are true. 我将域和文件夹替换为通用名称,但其他所有名称都是正确的。 (sorry about my english) (对不起我的英语)

i did search and test every solution i found, but my site refuse to redirect. 我确实搜索并测试了找到的每个解决方案,但我的网站拒绝重定向。

Problem is you're not capturing the URI in patter and using $1, %1 as back-reference. 问题是您没有在模式中捕获URI并使用$1, %1作为反向引用。

Try this rule in your root .htaccess as very first rule: 首先在根.htaccess中尝试以下规则:

RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM