¶ Out of the box, the Apache Web server that comes with OS X does not take any notice of .htaccess files (used to set passwords, rewrite URLs, point to custom error pages, etc). It took me a while to figure out how to get them working, so I’ve posted this for Google to soak up. Thanks to Jeremy and MacOSXHints for some pointers along the way.
The first step to getting .htaccess working is to edit your httpd.conf file. Open the Terminal, go to the Apache config directory and open httpd.conf. You will need to supply your admin password:
cd /private/etc/httpd/
sudo pico httpd.conf
Use ctrl-w to find ‘Override’. You need the second instance of the term so search twice. You should see:
# This controls which options the .htaccess files
in directories can
# override. Can also be "All", or any combination
of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride None
Change the setting to AllowOverride All then exit and save. At this point one would think the job is done, but each user has a conf file that would need changing too. Back in the terminal, move into the users directory and get a file listing:
cd users
ls
You should see a .conf file for each user on the system. As before, open the conf file for your username and change AllowOverride to AuthConfig:
sudo pico Clagnut.conf
<Directory "/Users/Clagnut/Sites/">
Options Indexes MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
Exit, save and restart Personal Web Sharing in your System Preferences. Your .htaccess files should now work. I don’t know the ins and outs of Apache under OS X so I’m not sure of the security implications here, but if, like me, you only use Personal Web Sharing for local development I don’t see any issues.
Update Leopard
I don’t have Leopard installed as yet so I can’t really help much at the moment other than to say your httpd.conf file is probably in /private/etc/apache2/httpd.conf.













Comments
1
Curious if this is for OS X Server 10.3.4. I cant get it to work plus i have “AllowOverride None” in my httpd.conf file 3 different times. And i dont have a .conf file for my username… ? any ideas?
2
Your article doesn’t make it clear how to deal with sites in directories other than the root (Documents) directory. I have many websites which all reside in the documents folder like:
Library/WebServer/Documents/website1/
Library/WebServer/Documents/website2/
Library/WebServer/Documents/website3/
... and I want to be able to ‘activate’ the .htaccess files in one or more of these sites. Do I need to do something like:
<Directory “/”>
Options FollowSymLinks AllowOverride FileInfo</Directory>
<Directory “/Library/WebServer/Documents/website1/”> AllowOverride FileInfo
</Directory>
... with a new entry for each website? ... or what is the best way to achieve this?
Thanks,
Galen
3
This solved my problem – thanks.
One thing though. Why did you put “AuthConfig” for the user conf file instead of “All”?
I got a configuration error message when I put AuthConfig, but everything worked fine when I changed both of them to All.
CHRIS
4
thank you! I kept banging my head against the wall trying to get htaccess working on my local osx dev sites, it’s the USER conf file you mentioned that did the trick.
many many thanks, and thank gawd for google.
5
Thanks alot to this site it helped me enable .htaccess files. Thank you!
6
Thank you, thank you, thank you.
Have been trying to get a customers site working on their backup server (can’t sign off until they know how to switch it to the backup server) for days.
Have hammered my head against anything solid in my office (note: monitor glass is tougher than a human’s skull) trying to figure out why it did not work. Especially after setting both servers up exactly the same and copying over the httpd.conf file.
Anyway, just a note, our servers seem to have been set up differently. Could not find the users folder, but we have a sites folder, in which there is a conf file for each site. In this file there is a <directory> entry with ‘AllowOverride None’. Change that to All, or whatever limitations you want to impose. That should do it.
Don’t really know Macs at all, so if anybody has any comments regarding this solution, please let me know
7
Thank you very much for this advice! After finding several other sites that claimed to explain how to get mod_rewrite working in apache on osx, none of them mentioned this little issue. Now I can get my rewrite rules working!
one extra note: for mod_rewrite to work, the user Options must also have FollowSymLinks set.
8
The correct syntax as mentionned by another poster is:
AllowOverride All AuthConfig
source:
http://httpd.apache.org/docs/1.3/mod/core.html#allowoverride
9
Just what I needed… Thanks a lot. It would’ve taken me ages to find that.
10
Great little article. I was struggling a little while back, but with some slight alterations to the ‘sites’ conf files instead of the ‘users’ (as I’m running Panther Server) , .htaccess is up and running. :)
11
In case that someone of you out there uses Virtual Hosts here is how to enable mod_rewrite on those:
<VirtualHost 127.0.0.1:80>
DocumentRoot /Users/stevan/Sites/karibik-invest.com
ServerName www.palm-hills.com.local
<Directory “/Users/stevan/Sites/karibik-invest.com”>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
Add your comment
Comments are now closed on this post. If you have more to say please contact me directly.