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'm setting my Apache2 Virtual Hosts, in a Debian Squeeze server, in this way:


Alias /whatever /var/www/

<VirtualHost *:80>
        VirtualDocumentRoot /var/www/%0 

        ErrorLog /var/log/apache2/
        CustomLog /var/log/apache2/ combined

<Directory /var/www/>
        AuthPAM_Enabled On
        AuthType basic
        AuthName "Authorization Required to proceed"
        AuthBasicAuthoritative off
        AuthUserFile /dev/null
        Require valid-user

I would like to serve the same site with two URL's: and

So to help this issue I've configured the Alias /whatever /var/www/ in the start of file. But I'm not aware if this is a good practice. And about the VirtualHost setting? There's something that can be done better?

And last question: there's a way to use variables inside of the file? As example repeat the %0 in other places than VirtualDocumentRoot?

Thanks in advance,

EDIT: I've got a new problem. With the global alias, all my virtualhosts will answer to the /whatever alias, and I only want the alias being applied on I'm struggling with RedirectMatch without success at this moment. I'm using redirect instead of alias because with alias the access and error log don't get in the virtualhost log file.

share|improve this question

You might want to put the Alias in it's own virtual host. For example:

<VirtualHost *:80>
    DocumentRoot /var/www/

    Alias /whatever /var/www/
    ErrorLog /var/log/apache2/
    CustomLog /var/log/apache2/ combined

That is how I would do it, but of course there are tons of ways do do things properly in Apache. If it works, it works...

As to your last question: You can't really use variables in config files (apart from a few exceptions), but there are third party modules that might be worth investigating. One is mod_macro: Another one that can be used to make config files more dynamic is mod_perl, but that is a really advanced topic.

share|improve this answer
Hello Krist, I've tried to put alias inside the <VirtualHost> scope but it disabled my; I think it should be inside the VirtualHost? – Vinícius Ferrão Mar 14 '13 at 16:47
Also don't forget about ServerName directive inside <VirtualHost> if you have more than one domain. – golja Mar 24 '13 at 0:02
Golja, the ServerName should be the real server name? Because my machine have one name and a lot of aliases. – Vinícius Ferrão Mar 31 '13 at 21:58
No, my mistake. You should have on "ServerName" directive in each VirtualHost, and you can have many ServerAlias directives. – Krist van Besien Apr 1 '13 at 8:42
Would this not be a case for a .htaccess directive ? – mika Apr 8 '14 at 12:54

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.