2012-09-04 14 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

相关问题