CakePHP .htaccess mod_rewrite 配置以排除特定文件夹/url [英] CakePHP .htaccess mod_rewrite configuration to exclude a particular folder/url
问题描述
我在服务器的子文件夹中安装了 CakePHP,我想在该子文件夹中安装另一个应用程序:
I have a CakePHP installation in a sub folder in my server, I want to install another application inside that subfolder:
root/public_html/subfolder/cake/
root/public_html/subfolder/app/
等等.现在我需要在那里安装一个自定义应用程序:
etc. now I need a custom application installed there:
root/public_html/subfolder/my_custom_application/
我的 .htaccess 中有这样的东西:
I have something like this in my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
如何将其配置为从该规则中排除my_custom_application"文件夹?
How can I configure it to exclude the "my_custom_application" folder from that rules?
我试过了:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule ((?!my_custom_application).*) app/webroot/$1 [L]
</IfModule>
但我明白了:
Error: The requested address '/y_custom_application' was not found on this server.
提前致谢.
毛里西奥.
推荐答案
如何从 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>
这篇关于CakePHP .htaccess mod_rewrite 配置以排除特定文件夹/url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!