Allowing .htaccess Use in Mac OS X

Allowing .htaccess Use in Mac OS X
Allowing .htaccess Use in Mac OS X

I found this solution to the problem I was having trying to use .htaccess files in my web server (Apache under Mac OS X Server) to block access to certain spam-dumping IP addresses. I was formatting the .htaccess files properly, and putting them in the right places in my server folder hierarchy. I had even modified my /etc/httpd/httpd.conf file to allow the .htaccess files to control access… or so I thought.

The trick turn out to be this answer from Robert Crow I found on the Apple Support forums (edited here for time, content, and gratuitous violence):

On Mac OS X 10.3 (client):
Navigate to the directory /etc/httpd/users/

On Mac OS X 10.3 Server:
Navigate to the directory /etc/httpd/sites/

Each site has a .conf file in this folder. For each site that you want .htaccess files to be processed, edit the file and change the line
AllowOverride None
to
AllowOverride All

AllowOverride only exits once in this file, so it’s easy to find.

To be able to access the .conf files mentioned, I downloaded and installed TinkerTool from http://www.bresink.de/osx/. Then I signed on as root, fired up TinkerTool, selected the checkbox “Show hidden and system files”, then pressed “Relaunch Finder”. Next, I navigated to the .conf files mentioned above and made the necessary change to the AllowOverride declarative (that is change “None” to “FileInfo”). In TinkerTool, I deselected the checkbox “Show hidden and system files”, then pressed “Relaunch Finder” again.

Log-out from the root account and you’re done.

Instead of using TinkerTool to access these directories, you can also click on your hard drive in the finder, then use the Shift-Apple-G “Go to folder…” shortcut, which will then pop up a sheet where you can type the directory you’re looking for, such as /etc/httpd/sites and it will take you there, and show you the contents of the hidden directory. TinkerTool, though is extremely useful for accessing and editing the .htaccess file, since once you save it with the dot at the front of the name, Mac OS X treats it as a unix system file, and hides it in the Finder.

Of course, after I’d set this up, I found that the fine folks at Apache really frown upon the use of .htaccess files unless you don’t have root access to the server. Of course, I do have root access, so I should probably re-implement this with their suggestion of a <Directory> entry in the main httpd.conf file