If you want to canonicalize your domains (e.g. redirect all domain.de to www.domain.de) you can use something like mod_rewrite:
<VirtualHost *>
ServerName www.domain.de
ServerAlias domain.de
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteRule /(.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>
The three Rewrite lines will basically:
- Check to see if the URL starts with 'www'
- If not, redirect to http://www.domain.de/[whatever]
If you go to 'domain.de' it will see that it doesn't start with 'www' and redirect to 'www.domain.de'.
If you want to apply this to every site you host, you can do like this:
<VirtualHost *>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteRule /(.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>
<VirtualHost *>
ServerName www.domain1.de
DocumentRoot /wherever/1
</VirtualHost>
<VirtualHost *>
ServerName www.domain2.de
DocumentRoot /wherever/2
</VirtualHost>
Then when someone tries to go to 'domain1.de' it will hit the first virtualhost, which will redirect them automatically to 'www.[whatever domain they typed in]'.
This way, if you go to 'domain1.de' it will see that it doesn't start with 'www' and redirect to 'www.domain1.de'. For 'domain2.de', it will redirect to 'www.domain2.de'. Every time you add a new site, you will automatically get this feature, which can be really handy if you're adding/maintaining a lot of websites.