Enable URL rewriting (mod_rewrite) using .htaccess files in ~/Sites on Lion

You should make sure that in your /etc/apache2/users/username.conf you have the following:

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

The FollowSymlinks and AllowOverride are essential here. While you are hinting at both in your question, maybe you did not configure these correctly in tandem.

Make sure in httpd.conf /private/etc/apache2/extra/httpd-userdir.conf is included as well. It is by default.

After any modifications, restart the web server for the changes to take effect.

If you are still having problems, maybe there is a problem with your actual rewrite rules. Were you using them in a .htaccess context before as well? Note that in a .htaccess, the rewrite rule regex is matched against a request URI without the leading slash and always relative to the directory where the .htaccess resides, whereas in a global httpd.conf the URI must match with a leading slash and is relative to the web root. Because assumedly you have your .htaccess in a subdirectory of ~/Sites, your rewrite rules might behave different from when the .htaccess resides in the web root of a (virtual) host.

To debug mod_rewrite you can enable rewrite logging. You should enable that in /etc/apache2/httpd.conf:

RewriteLogLevel 3
RewriteLog /path/to/rewrite.log

Adding Options +FollowSymLinks worked fine for me

Options +FollowSymLinks

RewriteEngine on
RewriteBase /
RewriteRule

I was experiencing a similar problem where my .htaccess file was being completely ignored while in a subfolder inside my ~/Sites directory under a VirtualHost that was setup correctly.

Having spent the last hour playing around with different configuration files and setting AllowOverride All in various places, I finally found out that the .htaccess file, while it looked like a .htaccess file in Finder, was actually a .htaccess.txt file with the extension hidden.

To check and change your .htaccess file, right click on it and choose Get Info and then make sure to remove any leading extension from the end, such as the one I had:

And now it works!


Below .htaccess entries fix for me

Options Indexes FollowSymLinks


<ifModule mod_rewrite.c>

RewriteEngine On
#RewriteBase /~charles/Sites/Timesheet/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]


</ifModule>