【发布时间】:2012-02-08 00:39:32
【问题描述】:
以下解决方案涵盖了必需的规则:
1) http://www.mydomain.com , http://www.mydomain.com/?p=home , http://www.mydomain.com/?p=home1 , http://www.mydomain.com/?qqq=home 始终为 http,即使键入的是 https 而不是 http;
2) 所有其余页面始终为 https,即使输入的是 http 而不是 https;
但实际上并不涵盖
3) //www.mydomain.com/administration/any_file_in_admin_folder.php 也应始终为 https(即使使用参数 ?p=home 等)。
RewriteEngine on
RewriteBase /
#determine if page is supposed to be http
#if it has p=home or p=home1 or qqq=home in querystring
RewriteCond %{QUERY_STRING} (^|&)(p=home1?|qqq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]
#all pages that are supposed to be http redirected if https
RewriteCond %{HTTPS} on
RewriteCond %{ENV:IS_HTTP} 1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#all other pages are sent to https if not already so
RewriteCond %{HTTPS} off
RewriteCond %{ENV:IS_HTTP} !1
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
如何对这段代码实施 3) 以使其正常工作? (我仍然没有运气,需要帮助)。 谢谢。
【问题讨论】:
标签: .htaccess mod-rewrite https flags