Php – Cannot get mod_rewrite to work on Mac OSX Mountain Lion

apache-2.2mac-osxmod-rewritePHP

I have tried everything I can think of and it still doesn't work. I am trying to get the example code from Larry Ullman's Advanced PHP book to work. His instructions were a bit lacking so I had to do some research. Here is what I have configured:

username.conf

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

httpd.conf

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

DocumentRoot "/Users/me/Sites"

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


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

.htaccess

<IfModule mod_rewrite.so>

RewriteEngine on
RewriteBase /phplearning/ADVANCED/ch02/

# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1

RewriteLog "/var/log/apache/rewrite.log" 
RewriteLogLevel 2
</IfModule>

Nothing has worked and it won't even log to the rewrite.log file. What have I done wrong? FYI even when I set up an extremely simple rule or use the root as the rewrite base, it still fails. I have also verified the mod_rewrite module is running. I am really angry.

Best Answer

Joel,

Hi - just came up against the same problem. Saw this post:

https://apple.stackexchange.com/questions/47526/enable-url-rewriting-mod-rewrite-using-htaccess-files-in-sites-on-lion

and changed my username.conf file from

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

to

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

and now mod_rewrite is working for me.

Related Topic