2012-02-29 117 views
3

所以我有以下重寫規則:的.htaccess重寫文件夾例外

RewriteRule ([^/]*)/([^/]*)/([^/]*)$ /index.php?grandparent=$1&parent=$2&page=$3 
RewriteRule ([^/]*)/([^/]*)$ /index.php?&parent=$1&page=$2 
RewriteRule ([^/]*)$ /index.php?page=$1  

但我需要這不是傳遞給一些子域的索引頁,所以我必須在此之前下列條件改寫:

RewriteCond %{REQUEST_URI} !^/css/.*$ 
RewriteCond %{REQUEST_URI} !^/js/.*$ 
RewriteCond %{REQUEST_URI} !^/admin/.*$ 

使尋找那些目錄(包括文件,可能是在這些目錄的子目錄)的任何文件時,該規則將不適用。但他們仍然不斷被重寫爲index.php

如何爲這些目錄設置例外?

回答

7

你的RewriteCond應該是這樣的:

RewriteCond %{REQUEST_URI} !^/(admin|js|css)/ [NC] 

此外,您必須使用LQSA標誌在所有的RewriteRule線這樣的:

# skip these paths for redirection 
RewriteCond %{REQUEST_URI} !^/(admin|js|css)/ [NC] 
RewriteRule^- [L] 

RewriteRule ([^/]*)/([^/]*)/([^/]*)/?$ index.php?grandparent=$1&parent=$2&page=$3 [L,QSA] 
RewriteRule ([^/]*)/([^/]*)/?$ index.php?&parent=$1&page=$2 [L,QSA] 
RewriteRule ([^/]*)/?$ index.php?page=$1 [L,QSA] 
+1

這工作對我來說,但令人驚訝的是沒有感嘆號像'RewriteCond%{REQUE ST_URI}^/(admin | js | css)/ [NC]'。我不是一個htaccess的mod重寫專家,但也許它應該被編輯? – cyborg86pl 2014-03-05 16:48:23

4

試試這個:

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^/(admin|css|js)/ 
RewriteRule . - [S=3] #skip the next 3 rules if the RewriteCond match 

RewriteRule ([^/]*)/?$ index.php?page=$1 [NC,L,QSA] 
RewriteRule ([^/]*)/([^/]*)/?$ index.php?&parent=$1&page=$2 [NC,L,QSA] 
RewriteRule ([^/]*)/([^/]*)/([^/]*)/?$ index.php?grandparent=$1&parent=$2&page=$3 [NC,L,QSA]