繁体   English   中英

htaccess与https重写冲突

[英]htaccess rewrite conflict with https

我有以下重写:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)$ user_home.php?domain=$1 [L,QSA]

可以很好地重写我的网址,但是现在我需要强制使用HTTPS,因此我正在使用以下代码:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

两者都可以工作,但不能一起工作。

mysite.com/somepage应该重定向到https://mysite.com/somepage

而是重定向到https://mysite.com/user_home.php?domain=somepage

我该如何工作?

这对我有用; 我猜您的问题可能是在服务器配置方面或其他地方。 通过AFAICT重写规则很好。

<VirtualHost *:80>
    ServerAdmin webmaster@crazysite.com
    DocumentRoot /var/www
    <Directory /var/www/>
        Options FollowSymLinks
        AllowOverride All 
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

<VirtualHost _default_:443>
    ServerAdmin webmaster@crazysite.com
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    SSLEngine on
    SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>

/var/www/.htaccess

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)$ user_home.php?domain=$1 [L,QSA]

/var/www/user_home.php

<?php
var_dump($_GET['domain']);

加载http://crazysite.com/test重定向到https://crazysite.com/test ,页面上的输出为

string(4)“测试”

暂无
暂无

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

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