Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a folder full of sites: /var/www

I have a domain:

I want to write a rule in my httpd.conf that will setup an alias for each site in /var/www.

For example: /var/www/hello/public can be accessed via

At the moment I am just writing my alias definitions manually, for each site: Alias /hello "/var/www/hello/public/"

share|improve this question
Why wouldn't you just make /var/www your DocumentRoot? – Shane Madden Mar 6 '12 at 22:36
Because the routing is to the public folder, not the root - /hello = /var/www/hello/public. – Oliver Joseph Ash Mar 6 '12 at 22:43
Ahh yeah, I missed that. In that case, Gabor's answer is the way to go. – Shane Madden Mar 6 '12 at 22:44

Easiest solution would be to use mod_vhost_alias instead. It does not do exactly what you described, but it's very close.

  1. Enable vhost_alias_module using whatever technique your distribution prefers (a2enmod vhost_alias on Debian-based distros).
  2. Add these directives to httpd.conf:

    UseCanonicalName Off
    VirtualDocumentRoot /var/www/%1/public
  3. Create a wildcard DNS entry for so any subdomain of is directed to your server.

Now accessing "" will load the site located in /var/www/hello/public.

Alternatively, as mentioned by Gabor, you can use mod_rewrite. The solution I'm going to outline assumes that you have no other content under

  1. Enable mod_rewrite using whatever mechanism your distro prefers (a2enmod rewrite on Debian-based distros).
  2. Add these directives to the VirtualHost for

    RewriteEngine On
    RewriteRule ^([^/]+)(.*) /var/www/$1/public/$2

This will rewrite a request for "" to /var/www/hello/public/steve.

share|improve this answer

Create a vhost for your domain and webroot. Write a rewrite rule instead of aliasing.

share|improve this answer
What would the RewriteRule look like in this case? – Oliver Joseph Ash Mar 6 '12 at 22:44
Well, a rewrite map can work here, but it's likely not quite as performant as the other solution. – 0xC0000022L Mar 6 '12 at 22:50
It would be useful to at least outline what the rewrite rule would look like. – pjmorse Mar 7 '12 at 14:03
I've outlined one below. – Insyte Mar 7 '12 at 22:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.