Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

mod rewrite - CakePHP .htaccess mod_rewrite configuration to exclude a particular folder/url

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/

I have something like this in my .htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

How can I configure it to exclude the "my_custom_application" folder from that rules?

I tried this:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    ((?!my_custom_application).*) app/webroot/$1 [L]
</IfModule>

But I get this:

Error:  The requested address '/y_custom_application' was not found on this server.

Thanks in advance.

Mauricio.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How to Exclude a Directory from CakePHP Routing:

I ran into the same problem as you. I struggled, but finally found something that worked.
(I'm replying because the answer above didn't work for me, but this did).

My directory structure:

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

What I added to CakePHP's default routing:

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

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:

Updated .Htaccess (this works for me)

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

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:

The Final Product (for a subfolder)

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...