Enable htaccess file in Mac OS X

Written by Guillermo Garron .
Date: 2013-05-03 13:05:00 -0400

Spanish version

Using your Mac for development of web applications or websites, is very easy as it already comes with Apache pre-installed, the problem is that .htaccess file does not work by default.

But it is easy to enable it.

First some changes in the main configuration file of Apache.

sudo vim /etc/apache2/httpd.conf

The first thing I will do is to change the Document root from the default /Library/WebServer/Documents to my Sites folder under my home directory.

So, look for these lines:

  • DocumentRoot "/Library/WebServer/Documents"
  • <Directory "/Library/WebServer/Documents">

And change them to:

  • DocumentRoot "/Users/your-username/Sites"
  • <Directory "/Users/your-username/Sites">

Of course instead of your-username insert there your real username.

I prefer to have it there, as I do not need root permissions to add content to that folder.

Enable .htaccess file in Mac OS X

In the same file, under the section <Directory "/Users/your-username/Sites"> look for:

  • AllowOverride None

And change it to:

  • AllowOverride All

Also edit this file:

sudo vim /etc/apache2/users/your-username.conf

And look for the same line AllowOverride None** and change it to *AllowOverride All

Then restart apache:

sudo apachectl restart

You are now ready to put files to ~/Sites/ folder and when you go to: http://localhost/ you will see those files appear, and if you add a .htaccess file, that is going to work.

Filled under: en|mac | permalink

If you enjoyed the article, please share it

twitter | facebook | google+ | linkedin | email | reddit