2012-02-12 135 views
-1

根據我的值IS_HTTP,我決定在下面的代碼之後,URL是否應該是https或http。htaccess從重寫文件中排除1個文件夾

我希望總是http(從https重定向)爲http://mydomain.com(具有空的QUERY_STRING),http://mydomain.com/?q=home,http://mydomain.com/?qq=home。 下面的代碼可以很好地適用於這樣的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不是從/開始的,但我可能是錯的)。

謝謝。

回答

0

,而不是這種情況:

RewriteCond %{REQUEST_URI} !^administration [NC] 

具備這個條件:

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

記住%{REQUEST_URI}始終以斜線開始,如果鍵入的瀏覽器,這樣可以有多個斜線。