Take over the “control” of some urls from CakePHP

By default, CakePHP takes full “control” of all URLs at the point where it is installed. Sometimes that behaviour is not desired. For example, my hoster defines an url like mydomain.com/stats where the statistics are available. If I install CakePHP in the root, this url no longer works resp. causes an error in CakePHP. The solution is to modify the .htaccess file in app/webroot. The original .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

And after the modification:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/stats/(.*)$
    RewriteRule ^.*$ - [L]
</IfModule>
# Begin CakePHP
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

The added rule is rather simple: if the url starts with /stats stop the interpretation of the .htaccess file. That’s it.

7 Comments

  1. fraisouille
    Posted August 17, 2006 at 6:16 pm | Permalink

    Rahhhh I tried so much to make this work !! thanks !!
    I had that problem with my phpmyadmin directory …

  2. Posted August 25, 2006 at 1:37 pm | Permalink

    Hmm..Didn’t need that in DH, stats/ and dh_phpmyadmin/

  3. Posted August 26, 2006 at 8:41 am | Permalink

    @oth: Hm, I’m also on DH, but for some reason I have to modify the htaccess file in a way similar to the one shown above to access the statistics.

  4. Posted September 14, 2006 at 9:41 am | Permalink

    what to do if it is not working? I tried couple ways to make it working bot I failed

  5. Posted September 14, 2006 at 6:08 pm | Permalink

    @korki: What is the problem?

  6. Posted September 15, 2006 at 9:11 pm | Permalink

    it’s not working, i have a statistics from my hosting provider and i did exactly what you wrote and it’s not working

  7. Posted September 18, 2006 at 9:45 am | Permalink

    @korki: It is possible that you have to add additional rules. My hosting provider is Dreamhost, and I need two rules to access the statistics:

    RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]
    RewriteCond %{REQUEST_URI} ^/failed_auth.html$


2 Trackbacks/Pingbacks

  1. […] Daniel Hofstetter (cakebaker): Take over the “control” of some urls from CakePHP: ”By default, CakePHP takes full ‘control’ of all URLs at the point where it is installed. Sometimes that behaviour is not desired. For example, my hoster defines an url like mydomain.com/stats where the statistics are available. If I install CakePHP in the root, this url no longer works resp. causes an error in CakePHP. The solution is to modify the .htaccess file in app/webroot. The original .htaccess file: […]

  2. […] Take over the “control” of some urls from CakePHP August 29th 2006 Posted to Internet Clipping, CakePHP https://cakebaker.wordpress.com/2006/08/17/take-over-the-control-of-some-urls-from-cakephp/ By default, CakePHP takes full “control” of all URLs at the point where it is installed. Sometimes that behaviour is not desired. For example, my hoster defines an url like mydomain.com/stats where the statistics are available. If I install CakePHP in the root, this url no longer works resp. causes an error in CakePHP. The solution is to modify the .htaccess file in app/webroot. The original .htaccess file: […]

%d bloggers like this: