.htaccess仅在某个子文件夹中重定向到HTTPS - 如果没有,则重定向到HTTP

时间:2014-06-11 23:45:24

标签: .htaccess http redirect https

在我的网站内,我有一个小商店。我希望.htaccess在商店网址或其任何子目录中将用户重定向到HTTPS。

http://www.example.com/services/shop/应该重定向到HTTPS。

http://www.example.com/services/shop/view-products/应该重定向到HTTPS。

每当用户不再在商店时,我希望将用户重定向到HTTP。

https://www.example.com/services/应该重定向到HTTP。

https://www.example.com/应该重定向到HTTP。

https://www.example.com/company/about-us/应该重定向到HTTP。

这是如何以干净和通用的方式完成的?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^services/shop/ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteRule !^services/shop/ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
相关问题