0

我有以下重写:

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.

我怎样才能让它工作?

4

1 回答 1

3

这对我有用;我猜您的问题可能出在服务器配置方面或其他地方。尽管 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并且页面上的输出是

字符串(4)“测试”

于 2013-11-03T06:53:03.530 回答