2013-05-14 100 views
1

我试图使用Bluehost提供的SSL通配符证书将一个子域切换到HTTPS。Mod_rewrite将HTTP切换到HTTPS

Web根包含许多子域,我只想影响测试。子域。

走进Web根,我已经写了下面的.htaccess文件:

RewriteCond %{SERVER_NAME} ^test.mydomain.com   
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}$1 

然而击中http://test.mydomain.com/admin/index.php不重定向我https://test.mydomain.com/admin/index.php

即使删除了SERVER_NAME的条件,它仍然无效。

我的重写规则不好吗?

回答

0

那么,首先我是在错误的.htaccess文件。我需要去我的子域的目录。

然后,简单地将它从HTTP切换到HTTP显然会导致某种类型的重定向到www。行为。

我不得不

A)保留不打算用于测试的现有规则。 B)添加测试。规则。

它增加了很多。

RewriteEngine On 

RewriteBase/

RewriteCond %{HTTP_HOST} !^test.example.com$ 
RewriteRule ^index\.php$ - [L] 

RewriteCond %{HTTP_HOST} !^test.example.com$ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

RewriteCond %{HTTP_HOST} ^test.example.com$  
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

RewriteCond %{HTTP_HOST} ^test.example.com$ 
RewriteCond %{REQUEST_URI} !^/test/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) /test%{REQUEST_URI} 

RewriteCond %{HTTP_HOST} ^test.example.com$ 
RewriteRule ^(/)?$ test/admin/index.php [L]