Mod_rewrite (CakePHP routing functionality) forbidden after Snow Leopard upgrade

13,790

Solution 1

How about the ownership/permissions of the files your pointing to? I'm more inclined to think Apache can't get to them rather than it being Apache at this point.

Edit with solution: Put Options +FollowSymLinks above RewriteEngine On

Solution 2

Adding FollowSymlinks to the htaccess didn't work for me so I googled a bit a found another solution

It turns out there is another Directory block in /etc/apache2/users/.conf in which you need to add FollowSymlinks to Options and change AllowOverride to All

<Directory "/Users/<your user>/Sites/">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

Restart apache and htaccess files and rewrite conditions should now work.

Solution 3

Ok, this is my solution distelled from the comments on this page:

Configuration:

  • Mac OS X 10.6.6
  • CakePHP 1.3.7

Solution: A combination of Matthieu Sadouni and Jason Strack, so:

Change /private/etc/apache2/users/{user}.conf to:

<Directory "/Users/{user}/Sites/">
    Options Indexes MultiViews FollowSymlinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

And change the Cake root .htaccess file to:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /~{user}/cake_1_3/
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

(Where {user} is your username and cake_1_3 is your cake directory)

UPDATE: Yes, I am new to Cake, so I started with the 15 minutes blog tutorial. That's how I found out you have to edit 2 other .htaccess files as well:

  • cake_1_3/app/.htaccess
  • cake_1_3/app/webroot/.htaccess

After RewriteEngine on add the line RewriteBase /~{user}/cake_1_3/ here as well.

Share:
13,790

Related videos on Youtube

Ryan Ballantyne
Author by

Ryan Ballantyne

Updated on September 17, 2022

Comments

  • Ryan Ballantyne
    Ryan Ballantyne over 1 year

    I am using the standard Apple-provided installations of PHP 5.3 and Apache 2 to do web development on a Mac Pro that I just upgraded to Mac OS X 10.6 (Snow Leopard). The upgrade went well enough, if I ignore the fact that it destroyed my ability to get work done. ;)

    After the update, the CakePHP application I was developing started giving me 403 Forbidden errors when accessed. Based on the errors in the log file, I've determined that Apache is choking on the mod_rewrite rules in Cake's .htaccess file. Here's the file, in its entirety:

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

    It's not that the rules themselves are wrong, but that Apache is forbidding the use of mod_rewrite altogether. All other pages on the machine work fine, and the 403 errors go away if I comment out the .htaccess file (but nothing works, of course).

    In my httpd.conf file, I've tried changing this:

    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
    </Directory>
    

    To this:

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Allow from all
    </Directory>
    

    ...which has no effect.

    I don't know much about Apache configuration files, and I'm quite stuck on this. In fact, I know little enough that I'm not sure which information about my setup is needed to enable people to provide useful answers. I'm just using the vanilla OS X setup, nothing fancy.

    Googling has yielded no fruits for me this time, so I'm turning to you. Any ideas?

  • Ryan Ballantyne
    Ryan Ballantyne over 14 years
    I probably should have mentioned this in the question, but that's the first thing I tried. The error logs point to mod_rewrite, and when mod_rewrite isn't used, the error goes away...
  • Xorlev
    Xorlev over 14 years
    How about selectively commenting rewrite rules? Does one or the other stop it?
  • Ryan Ballantyne
    Ryan Ballantyne over 14 years
    Commenting out both rules does not stop the error. Commenting out the "RewriteEngine On" line does.
  • Xorlev
    Xorlev over 14 years
    Try putting Options +FollowSymLinks Above RewriteEngine On. I know you have it in Directory, but it -may- help.
  • Ryan Ballantyne
    Ryan Ballantyne over 14 years
    It makes absolutely no sense, but it worked, so I'll take it. Thanks!