Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm setting my Apache2 Virtual Hosts, in a Debian Squeeze server, in this way:

filename: whatever.mydomain.com

Alias /whatever /var/www/whatever.mydomain.com

<VirtualHost *:80>
        ServerAlias whatever.mydomain.com
        ServerAdmin myemail@mydomain.com
        VirtualDocumentRoot /var/www/%0 

        ErrorLog /var/log/apache2/whatever.mydomain.com-error.log
        CustomLog /var/log/apache2/whatever.mydomain.com-access.log combined
</VirtualHost>

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

I would like to serve the same site with two URL's: whatever.mydomain.com and www.mydomain.com/whatever

So to help this issue I've configured the Alias /whatever /var/www/whatever.mydomain.com 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 www.mydomain.com. 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

1 Answer 1

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

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAdmin myemail@mydomain.com
    DocumentRoot /var/www/whatever.mydomain.com

    Alias /whatever /var/www/whatever.mydomain.com
    ErrorLog /var/log/apache2/www.mydomain.com-error.log
    CustomLog /var/log/apache2/www.mydomain.com-access.log combined
</VirtualHost>

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: http://people.apache.org/~fabien/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 www.mydomain.com/whatever; I think it should be inside the www.mydomain.com 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 at 12:54

Your Answer

 
discard

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.