溶液下方覆盖所需的规则:htaccess的:重定向HTTP到HTTPS或https为http取决于URL
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)即使输入的是http而不是https,其余所有页面始终为https,
但在实践中不涵盖
3)//www.mydomain.com/administration/any_file_in_admin_folder.php
应该总是HTTPS以及(即使有参数P =家庭等)。
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和.htpasswd文件)页面管理/索引。 PHP重定向到404错误页面。 IE说(如果我输入了错误的密码):另外,尝试使用ErrorDocument来处理请求时遇到404 Not Found错误。如果我输入正确,404错误页面显示没有错误。这是怎么回事?没有密码--everythigsOK。 – Haradzieniec 2012-02-07 20:05:53
@Haradzieniec是否为'401错误'定义了单独的文档? – ThinkingMonkey 2012-02-07 20:18:46
@Haradzieniec它的工作原理是在第二和第三块(指向'http'协议)中添加'RewriteCond%{REQUEST_URI}!/ administration/[NC]'来检查URI中没有'administration'。 – ThinkingMonkey 2012-02-07 20:20:30