2008-08-06 86 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]