我需要所有的请求到现场www和只有某些网页重定向HTTPS不WWW,由于某种原因,SSL证书由我们的客户买了不包括WWW。 环顾四周后,我成功地完成了它。 但是,什么情况是,一旦我们参观了一个安全的网址页面,其他页面将留在HTTPS。 以下是我迄今为止在the.htaccess:
#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上,而不是属于中列出的网址的一部分。 但我不熟悉,在所有正则表达式和重写规则。 一些帮助将不胜感激。
尝试使用此代码来代替:
# 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]
文章来源: htaccess redirect to ssl only for certain pages and www non secure for the other pages