2014-02-24 26 views
1

沿HTTPS重定向到http除了一个网页,我使用htaccess的的.htaccess在我的域名之一,WWW到非www

RewriteCond %{SERVER_PORT} ^443$ [OR] 
RewriteCond %{HTTPS} on [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] 
RewriteRule (.*) http://example.com/$1 [R=301,L] 

其中全部重定向HTTPS访问http以及WWW到非www域名。

现在,我想secure.php页面也使用https协议而不是http协议的WWW重定向到非www。

我可以用下面的线达致这...

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

RewriteCond %{HTTPS} off 
RewriteCond %{SCRIPT_FILENAME} \/secure\.php [NC] 
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L] 

RewriteCond %{HTTPS} on 
RewriteCond %{SCRIPT_FILENAME} !\/secure\.php [NC] 
RewriteRule (.*) http://%{HTTP_HOST}/$1 [R=301,L] 
在我的第一个htaccess的

如果用户访问https://www.example.com然后重定向到http://example.com在单一的重定向。

修改后,以确保secure.php页,在第二htaccess的考虑情况下,如果用户访问http://www.example.com/secure.php - >重定向到http://example.com/secure.php - >重定向到https://example.com/secure.php 在这里,我得到两个重定向。

PLS建议我的俱乐部我的标准像我的第一个htaccess的使用[OR],所以不是在所有情况下,它atmost使用一个重定向达到最终页哪有。

回答

0

尝试:

RewriteCond %{REQUEST_URI} !^/secure\.php 
RewriteCond %{HTTPS} on [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] 
RewriteRule (.*) http://example.com/$1 [R=301,L] 

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] 
RewriteRule ^(secure\.php.*) https://example.com/$1 [R=301,L]