2012-09-04 18 views
2

我需要將所有請求重定向到網站www和只有某些網頁https沒有www,因爲由於某些原因我們的客戶購買的ssl證書不包括www。 環顧四周後,我設法完成了大部分工作。但是,一旦我們訪問了安全的網頁頁面,其他頁面將保持在https上。 這裏是我迄今爲止在the.htaccess:htaccess重定向到ssl僅用於某些網頁和www不安全的其他網頁

#Redirect to www 
RewriteCond %{HTTPS} =off 
RewriteCond %{HTTP_HOST} ^[^./]+\.[^./]+$ [NC,OR] 
RewriteCond %{HTTP_HOST} ^([^./]+)\.[^./]+\.[^./]+$ [NC] 
RewriteCond %1 !=www [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 


# Force SSL on checkout login account and admin pages 
RewriteCond %{HTTPS} =off 
RewriteCond %{REQUEST_URI} checkout|login|my-account|administrator|webshop 
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ https://%1/$1 [R=301,L 

我想將重定向到www非安全如果HTTPS上,而不是屬於中列出的網址的一部分。但我並不熟悉正則表達式和重寫規則。 一些幫助將不勝感激。

回答

1

嘗試使用此代碼來代替:

# Force SSL on checkout login account and admin pages 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} checkout|login|my-account|administrator|webshop 
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC] 
RewriteRule ^(.*)$ https://%2/$1 [R=301,L,QSA] 

# Remove SSL on other pages 
RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} !checkout|login|my-account|administrator|webshop 
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC] 
RewriteRule ^(.*)$ http://www.%2/$1 [R=301,L,QSA] 

# Force www for non https 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA] 
+0

非常感謝你的幫助。但SSL指令導致安全URL只能登陸主頁。 也許,這是由Joomla自己的重寫規則與這些規則衝突引起的? – JeffT

+0

是的,它可以衝突,也確保這些規則是您的htaccess中的第一個。 – Oussama

相關問題