301 Redirect in Apache2 VirtualHost Setting
To come clean in terms of SEO and peace of mind don’t simply pont your domains to one IP and leave it like that. Be specific on the URL you want the spiders and your users to use! Decide if you want to go with www.tomschlenkhoff.com or etter tomschlenkhoff.com or tomschlenkhoff.de. Once you did, set up your VirtualHost files in the sites-available folder like that:
NameVirtualHost *
<VirtualHost *>
ServerName www.tomschlenkhoff.com
ServerAdmin blogmaster@tomschlenkhoff.com
DocumentRoot /var/www/tomschlenkhoff
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
<VirtualHost *>
ServerName tomschlenkhoff.com
ServerAlias tomschlenkhoff.de www.tomschlenkhoff.de
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
RedirectMatch 301 (.*) http://www.tomschlenkhoff.com$1
</VirtualHost>
That’s the info I was looking for. Thx a lot.
Thanks for sharing this. It works great. It was just what I was looking for. Great for consolidating many domains.
Just a note, that I tried it without the ErrorLog and CustomLog and that seemed to cause it to not work on my machine…
So, word to the wise, leave those bits in!
Exactly what I was after, thanks for sharing this. Saves looking through documentation!
Opposite to what Jeff mentioned, I left Error/Custom logging out and it’s working fine.
[...] Redirection 301 via virtualhost [...]