apache – .htaccess指令*不*重定向某些URL
在一個很大程度上依賴於.htaccess RewriteRules的PrettyURL(在我的情況下為CakePHP)的應用程式中,如何正確地設定指令來排除某些目錄從這個重寫?那是:
/appRoot/.htaccess app/ static/
預設情況下,每個對/ appRoot / *的請求都被重寫,以便被app / webroot / index.php所接受,在這裡它將被分析並且正在呼叫相應的控制器操作.這是由.htaccess中的這些指令完成的:
RewriteBase /appRoot RewriteRule ^$app/webroot/[L] RewriteRule (.*) app/webroot/$1 [L]
我現在想排除一些目錄,如靜態/從這個重寫.我在Cake RewriteRules之前嘗試過:
RewriteCond $1 ^(static|otherDir).*$[NC] RewriteRule (.*) - [L]
到目前為止,它的工作原理是不再重寫請求,但現在所有請求都被跳過,即使是不合法的Cake請求也不能匹配^(static | otherDir)* $.
我嘗試了這些規則的幾個變體,但不能讓它按照我想要的方式工作.
正確的答案是…
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
並通過蛋糕處理.現在有了這個,我想這樣做會有所改變(Mike的建議稍作修改,未經測試):
RewriteCond $1!^(a|bunch|of|old|directories).*$[NC] RewriteRule ^(.*)$ app/webroot/$1 [L]
http://stackoverflow.com/questions/3157/htaccess-directives-to-not-redirect-certain-urls