htaccess的重定向到SSL仅适用于​​某些网页和WWW不保证能用于其他页面 [英] htaccess redirect to ssl only for certain pages and www non secure for the other pages

查看:129
本文介绍了htaccess的重定向到SSL仅适用于​​某些网页和WWW不保证能用于其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重定向所有请求到现场WWW只是在某些页面,HTTPS加www,由于某种原因,SSL证书由客户买的不包括WWW。 后环顾四周,我设法完成大部分。但发生的事情是,一旦我们参观了一个安全的网址页面,其他页面将留在HTTPS。 这里是我迄今为止在the.htaccess:

I need to redirect all requests to the site to www and only certain pages to https without www, since for some reason the ssl certificate bought by our customer doesn't cover www. After looking around I managed to accomplish most of it. But what happens is once we have visited a secure url page, the other pages will stay on https. Here is what I have so far in 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上,而不是归属于上市网址的一部分。但我不熟悉所有与正则表达式和重写规则。 一些帮助将大大AP preciated。

I miss the part that will redirect to www non secure if https is on and not belonging to the listed urls. But I'm not familiar at all with regex and rewrite rules. Some help will be greatly appreciated.

推荐答案

尝试使用这种code来代替:

Try using this code instead :

# 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的重定向到SSL仅适用于​​某些网页和WWW不保证能用于其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆