Domain Redirects
January 16th, 2009 Category: ApacheAvoid Double Content
There are two reasons to redirect e.g. mydomain1.de to www.mydomain1.de:
- It avoids detecting search machines “double content”
- I personally prefer having one unique URL for a homepage, also if a user enters mydomain1.de he will be redirected to www.mydomain1.de
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.de$ [NC]
RewriteRule ^(.*) http://www.mydomain.de/$1 [L,R=301]
The redirect is defined as 301 “permanent”. Please note that these rewrite settings only work if the correct setting for “AllowOverride” is done within the Apache settings of your host or virtual host configuration.
Redirect Domain to another Domain
If you want to redirect a complete domain, here mydomain1.de including subdomains to another domain e.g. mydomain2.de put the following code into the .htaccess of the web root directory of mydomain1.de:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)mydomain1\.de$
RewriteRule ^(.*)$ http://www.mydomain2.de/$1 [R=301,L,NC]
Using this rewrite condition all hosts *.mydomain1.de including mydomain1.de will be redirected to www.mydomain2.de. Everything behind .de/ will be kept.
Furthermore the redirect is defined as 301 which means permanent redirect. This will avoid that search machines like Goole will treat you with “double content”.
Hint
Be sure you have enabled “Options FollowSymLinks” or Options “SymLinksIfOwnerMatch” in your Apache or virtual host config. Otherwise mod rewrite will not work!
Working with Apache/2.2.3