veni vidi Scripsi

Mac OS X Apache Mass VHosts (with support for htaccess and symlinks)

A while ago I wrote two posts, one on using Twig and another on using htaccess with Mac's Apache. I was reasonably happy with the described setups until I discovered that when I used something like <link rel="stylesheet" href="/style.css" media="all"> in my HTML it wouldn't work because my site was running at the default http://localhost/~heleen/website/index.html and so it would map the 'root' slash to http://localhost/ rather than http://localhost/~heleen/website/. I found a solution to this using vhosts, which works really well. But then I had to add another website, and another, and realised that surely there should be an easier way continue.

Getting htaccess to work on a Mac (Lion) with Apache and using symlinks

Edit (sudo) /etc/apache2/users/[your-username].conf:

  1. Add Doc­u­men­t­Root "/Users/[your-username]/Sites/" at the top of the file;
  2. Add Fol­lowSym­Links to the Options;
  3. Change Al­lowOver­ride None to Al­lowOver­ride All;
  4. Change Deny from All to Allow from All.


<Directory "/Users/[your-username]/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Deny from All


DocumentRoot "/Users/[your-username]/Sites/"
<Directory "/Users/[your-username]/Sites/">
   Options Indexes MultiViews FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from All

Restart Apache: sudo apachectl graceful