Digital Notepad

Internet, Mobility and Serious Geekery

301 Redirect in Apache2 VirtualHost Setting

August6

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>

posted under Tech
4 Comments to

“301 Redirect in Apache2 VirtualHost Setting”

  1. On January 11th, 2009 at 16:04 Seweryn Niemiec Says:

    That’s the info I was looking for. Thx a lot.

  2. On February 4th, 2009 at 19:50 Jeff Richards Says:

    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!

  3. On June 24th, 2009 at 8:29 Nathan M. Says:

    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.

  4. On September 15th, 2009 at 10:27 Libre jusqu'au bout - Un blog utilisant WordPress » Blog Archive » VirtualHost et VirtualDocumentRoot Says:

    [...] Redirection 301 via virtualhost [...]

Email will not be published

Website example

Your Comment: