2008-08-06 85 views
18

在一個嚴重依賴.htaccess RewriteRules爲其PrettyURL(我的情況爲CakePHP)的應用程序中,如何正確設置指令以從此重寫中排除某些目錄?那就是:.htaccess指令不*重定向某些URL

/appRoot/.htaccess 
     app/ 
     static/ 

默認情況下,以每/appRoot/*請求被改寫由app/webroot/index.php,在那裏它被分析,並正在調用相應的控制措施有所回升。這是由這些指令在.htaccess完成:

RewriteBase /appRoot 

RewriteRule ^$ app/webroot/  [L] 
RewriteRule (.*) app/webroot/$1 [L] 

我現在要排除的幾個目錄,如靜態/從此改寫。我試着用這個之前蛋糕的RewriteRules:

RewriteCond $1 ^(static|otherDir).*$ [NC] 
RewriteRule (.*) - [L] 

它工作在迄今爲止的請求不再改寫,但現在所有請求都被跳過,這不應該匹配^(static|otherDir).*$即使是合法的蛋糕請求。

我嘗試了這些規則的幾種變體,但無法按照我想要的方式使其工作。

回答

6

與正確答案iiiiis ...

RewriteRule ^(a|bunch|of|old|directories).* - [NC,L] 

# all other requests will be forwarded to Cake 
RewriteRule ^$ app/webroot/ [L] 
RewriteRule (.*) app/webroot/$1 [L] 

我還是不明白爲什麼在根目錄下的index.php文件即使在發生這些指令最初叫。它現在位於

/appRoot/app/views/pages/home.ctp 

並通過Cake進行處理。有了這個現在,我想這也會起作用(Mike的建議略有改動,未經測試):

RewriteCond $1  !^(a|bunch|of|old|directories).*$ [NC] 
RewriteRule ^(.*)$ app/webroot/$1 [L] 
1

從以前的規則刪除[L]:

RewriteBase /appRoot 

RewriteRule ^$ app/webroot/     
RewriteRule (.*) app/webroot/$1 

[L]表示「在這裏停止重寫的過程,不應用任何重寫規則。」

1

你能滿足條件適用於以下規則,但是與否定,如(有一些變體,我不是在回憶的.htaccess規則太好,所以標誌可能是錯誤的):

RewriteCond $1 !^(static|otherDir).*$ [NC] 
RewriteRule ^$ app/webroot/ [L] 

RewriteCond $1 !^(static|otherDir).*$ [NC] 
RewriteRule ^$ app/webroot/$1 [L]