题
在一个应用程序,很大程度上依赖于 .htaccess
RewriteRules其PrettyURLs(Cake在我的情况),我怎么正确地设立的指令中排除某些目录,从此改写?这是:
/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).*$
.
我试了几个变化,这些规则,但不能得到它的工作我想要的方式。
解决方案
正确的答案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
并处理通过蛋糕。这个地方现在,我想这会有作,以及(略有改变版的麦克的建议,未经测试):
RewriteCond $1 !^(a|bunch|of|old|directories).*$ [NC]
RewriteRule ^(.*)$ app/webroot/$1 [L]
其他提示
你能不适用的条件下以下规则,但是与否定,和在(与一些变异了,我不太好记忆。要规则,这样的标志可能是错的):
RewriteCond $1 !^(static|otherDir).*$ [NC]
RewriteRule ^$ app/webroot/ [L]
RewriteCond $1 !^(static|otherDir).*$ [NC]
RewriteRule ^$ app/webroot/$1 [L]
删除[L]从前的规则:
RewriteBase /appRoot
RewriteRule ^$ app/webroot/
RewriteRule (.*) app/webroot/$1
[L]手段"停止改写的过程在这里并不适用任何更重写规则。"
不隶属于 StackOverflow