htaccess从rewriterules中排除1个文件夹

时间:2012-02-12 18:22:21

标签: http .htaccess mod-rewrite https directory

根据我的值IS_HTTP,我决定在下面的代码之后,URL是否应该是https或http。

我希望始终为http://mydomain.com(具有空的QUERY_STRING),http://mydomain.com/?q=homehttp://mydomain.com/?qq=home的http(从https重定向)。 以下代码适用于此类URL,它将IS_HTTP设置为1.一切都很完美。但我还希望管理文件夹的URL始终是httpS,所以我想从该块中排除这些URL。

这就是我将第二个字符串添加到下面的代码中的原因,但它不会阻止此类URL应用RewriteRule ^ - [E=IS_HTTP:1]。为什么呢?

#determine if page is supposed to be http
RewriteCond %{REQUEST_URI} !^administration [NC]
#if it has q=home or qq=home in querystring
RewriteCond %{QUERY_STRING} (^|&)(q=home|qq=home)(&|$) [NC,OR]
#or if query string is empty
RewriteCond %{QUERY_STRING} ^$
#set env var to 1
RewriteRule ^ - [E=IS_HTTP:1]

同样,我希望在https://mydomain.com/administration/index.php之前停止RewriteRule ^ - [E=IS_HTTP:1]和文件夹/管理中的所有其他文件 为什么上面的代码不会阻止它们?

我试过的第二个字符串是:

RewriteCond %{REQUEST_URI} !^administration [NC]
RewriteCond %{REQUEST_URI} !^/administration [NC]

但它们都不起作用。 (我相信/这里不需要/因为REQUEST_URI不是从/开始,但我可能错了)。

谢谢。

1 个答案:

答案 0 :(得分:0)

而不是这个条件:

RewriteCond %{REQUEST_URI} !^administration [NC]

有这个条件:

RewriteCond %{REQUEST_URI} !^/+administration [NC]

请记住%{REQUEST_URI}总是以斜杠开头,如果在浏览器中以这种方式输入,则可以有多个斜杠。

相关问题