2014-02-24 28 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]