Vanja D.
Vanja D.

Reputation: 854

Exclude a root folder from CakePHP app

I am trying to exclude a first level directory from Cake (root folder app), as it should hold a different app.

/ holds the app

/development/ holds the tested version of the app

The directory structure:

Public folder

.htaccess [modified]
app
    .htaccess [unmodified]
    webroot
        .htaccess [unmodified]
        index.php [unmodified]
        ...
    ...
lib
    Cake
    ...
development
    app
        webroot
            index.php [dumps $_SERVER for test purposes]

So, my development structure still doesn't have an app inside (nor .htaccesses), just to test if my root .htaccess works.

This is my modification of the root .htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine on

   RewriteCond %{REQUEST_URI} ^/development.*
   RewriteRule (.*) - [L]

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

What happens:

/development/ shows the apache index of development folder

/development/app/ shows the apache index of app folder

/development/app/webroot shows the root app (request is captured in spite of the development url match).

/development/app/webroot SHOULD show me my /development/app/webroot/index.php file, right?

What the hell am I missing here?

Upvotes: 1

Views: 2956

Answers (1)

Vanja D.
Vanja D.

Reputation: 854

This turned out to be an oddball bug on my server.

The resulting .htaccess which works now is:

<IfModule mod_rewrite.c>
   RewriteEngine on

   RewriteCond %{REQUEST_URI} !^/development(?:$|/)
   RewriteRule    ^$ app/webroot/    [L]

   RewriteCond %{REQUEST_URI} !^/development(?:$|/)
   RewriteRule    (.*) app/webroot/$1 [L]

</IfModule>

For reasons unknown to me, if I SSH'd to my user account and edited the .htaccess files through the command line, it wouldn't work!

When I uploaded the same files (via SFTP), it started working properly.

I am using cPanel (11.34.1) on CentOS (5.9).

Another example: if you wish to "ignore" multiple sub-folders on a CakePHP installation, you can use this pattern:

<IfModule mod_rewrite.c>
   RewriteEngine on

   # /development, /version1.5 and /version1.8 directories
   # they all hold independent apps
   # or completely non-cake-related content

   RewriteCond %{REQUEST_URI} !^/(?:development|version1\.5|version1\.8)(?:$|/)
   RewriteRule    ^$ app/webroot/    [L]

   RewriteCond %{REQUEST_URI} !^/(?:development|version1\.5|version1\.8)(?:$|/.*)
   RewriteRule    (.*) app/webroot/$1 [L]

</IfModule>

Note that both RewriteCond instructions are identical.

Upvotes: 3

Related Questions