且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CakePHP .htaccess mod_rewrite 配置以排除特定文件夹/url

更新时间:2023-09-12 11:47:52

如何从 CakePHP 路由中排除目录:

我遇到了和你一样的问题.我很挣扎,但终于找到了一些有用的东西.
(我回复是因为上面的答案对我不起作用,但确实如此).

我的目录结构:

root/public_html/app/
root/public_html/lib/
root/public_html/plugins/
root/public_html/vendors/
root/public_html/directory_to_exclude/

我添加到 CakePHP 的默认路由中的内容:

RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)

实际上,我需要允许人们单独访问子文件夹(因为它有一个单独的应用程序).此外,就我而言,我默认从根目录提供 CakePHP 应用程序.
这是我的 CakePHP 2.x htaccess 的样子:

Effectively, I needed to allow people to access the subfolder separately (since that has a separate application). Also, in my case, I'm serving a CakePHP application by default from the root directory.
So here's what my CakePHP 2.x htaccess looks like:

更新了 .Htaccess(这对我有用)

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI} !^/directory_to_exclude/(.*)
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

就您而言,我知道您需要在子文件夹中使用它;这是我调整后的 htaccess 我没有机会测试这个,但我相信这(或接近的东西)会起作用:

In your case, I understand you need this to work in a subfolder; here's my adjusted htaccess I didn't have a chance to test this, but I believe this (or something close) will work:

最终产品(子文件夹)

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI} !^/subfolder/directory_to_exclude/(.*)
   RewriteRule    ^$ subfolder/app/webroot/    [L]
   RewriteRule    (.*) subfolder/app/webroot/$1 [L]
</IfModule>