只在一个页面中将http重定向到https,其他页面https重定向到http

问题描述:

我希望将某些页面从http重定向到https(具有表单和登录页面的页面)以及其他页面,并将https重定向到http。只在一个页面中将http重定向到https,其他页面https重定向到http

我如何在没有为每个页面编写所有规则?

+0

它不是固定既保护了登录页面,如果认证cookie是到http网页访问。用身份验证表单管理网站的唯一安全方法是使用https无处不在和hsts。 – Tom

您可以使用/root.htaccess如下:

RewriteEngine on 

#redirect /login from http => https# 
RewriteCond %{HTTPS} off 
RewriteRule ^login https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] 
#redirect any other request excluding /login from https to http# 
RewriteCond %{HTTPS} on 
RewriteRule !^login http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]