I have the following folder structure on my Apache



I have defined a virtual host for each.

So if I type in www.x.tt in my browser I get to the www.x.tt site. And the same for www.y.tt.

But now my question! If I type in the server address or the server host name I get to the ../var/www directory but I want that the user will be redirected to the www.x.tt site!

Do I have to create a new virtual host for this problem or is it also possible only to add a .htaccess Rule?!


2 Answers 2


You don't mention how you configured your virtual hosts, but I guess that you've done it following the "traditional" Debian-way - by creating files in /etc/apache/sites-available/ and then using a2ensite to enable the virtual host.

If so, you may edit your /etc/apache/sites-available/default file and put the virtual host you want to be the default one in it. For example:

<VirtualHost _default_:80>
  ServerName www.x.tt
  ServerAlias x.tt
  DocumentRoot /var/www/www.x.tt/htdocs

More information about the _default_ keyword.

EDIT : If you're using name-based virtual hosts, just make sure that the configuration for the x.tt vhost is loaded first - this way it will be the default catch-all address.

  • _default_ doesn't do anything when using name-based virtual hosts, just IP-based. @Matthias, which method are you using? Jun 30, 2012 at 19:37
  • Yes, indeed. That was a bad assumption from me. Edited my answer above. Jun 30, 2012 at 20:30

You have to user a ServerName and a ServerAlias in your vhost configuration file

<VirtualHost *:80>

    ServerName your.domain.com
    ServerAlias your.domain.com www.your.domain.com

Otherwise, if you want to have a default website for the unspecified vhost, you have to create an vhost for that. You can check that with the command:

apache2ctl -S
  • Javier, I'm pretty sure he's asking about a default catch-all address, so I think the _defaut_ keyword would be more appropriate in this case. Jun 30, 2012 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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