The mod_vhost_alias offers a powerful way to map URL and file locations.

Do you remember in school, when you had an user account on the school’s server and each student could host a website out of his home’s www folder ?

Well, the school admin was using Apache’s mod_userdir to map urls such as school.com/student/index.html to /school/server/student/www.

I decided I wanted to do something similar on my dev setup except that, instead of having several users, I have several projets.

So, let’s say I have my computer setup to know that *.sam.net is my local machine and I have several project in /Users/sam/webdev

I want

  • dev1.sam.net >> /Users/sam/webdev/dev1
  • dev2.sam.net >> /Users/sam/webdev/dev3
  • dev3.sam.net >> /Users/sam/specialdev3

I can now create two Virtual Hosts instead of three.

In the first one, I will setup the dev3 mapping as it is an exception.

In the second one (should be loaded last by Apache) I’ll add :

<VirtualHost *:80>
ServerAlias *.adssoft.fr
UseCanonicalName Off
VirtualDocumentRoot /Users/sam/%1

Test your config and restart Apache

apachectl configtest
sudo apachectl restart
Got it working thanks to the help from this post
Filed under: Système

Tagged with: , , , , , ,

Liked this page?

Tweet it

Subscribe to the RSS feed or sign up for the newsletter now.

Posts related to Apache : mod_vhost_alias

Name (required)

Email (required)


Leave a Reply

  • About Me

    photo of Samantha Halfon Samantha Halfon
    Software Engineer
    blueKiwi software
    Paris, France
    I enjoy playing with my computer(s), listening to Bob Dylan (and related artists) and watching movies (especially if they were directed by Martin Scorsese or John Cassavetes). Sometimes, I play a little guitar... If not doing any of the above, I am either riding a small red bike around Paris, or, making videos. About my videomaking please check out World Wide Angle and its blog.