【问题标题】:http to http redirect virtual host in apachehttp到http重定向apache中的虚拟主机
【发布时间】:2014-04-11 10:25:30
【问题描述】:

您好,我在 CentOS 6.5 中使用 apache 2.4 和 PHP 5.5 配置服务器 我安装了 SSL 证书,一切正常。

在另一台服务器上,我对 htaccess 文件进行了 http 到 https 重定向。 我在我的新服务器上进行了测试,但没有用,这是我的配置:

我的 .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>

我的虚拟主机文件:

    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>

我将域和文件夹替换为通用名称,但其他所有内容都是正确的。 (对不起我的英语)

我确实搜索并测试了我找到的每个解决方案,但我的网站拒绝重定向。

【问题讨论】:

    标签: apache .htaccess https laravel virtualhost


    【解决方案1】:

    问题是您没有以模式捕获 URI 并使用 $1, %1 作为反向引用。

    在您的根 .htaccess 中尝试此规则作为第一条规则:

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

    【讨论】:

    • 没用,但我可以看看我是否放了 www。在子域之前,重定向到没有 www 的子域。并使用 https !!!,但无需您的代码即可使用。
    • 现在我需要不带 www 的重定向。到。
    • 你的意思是你想从 URL 中删除 www 并且不想要 https 或者两者都想要?你能澄清一下吗?
    • 我都需要,删除 www 并重定向到 https
    • 好的,抱歉,我没有“AllowOverride All”,我把它放在了我的 htaccess 配置中,现在我需要两个 rukes,删除 www 并重定向 https。
    猜你喜欢
    • 2016-07-16
    • 2017-06-04
    • 1970-01-01
    • 2018-10-12
    • 2010-10-06
    • 2017-04-08
    • 2019-08-13
    • 2018-07-08
    • 2014-01-19
    相关资源
    最近更新 更多