Note: The forum will not allow me to post links until my post count is higher so in this post replace h++p with http and tonyswebdesign with your own domain(s)
If you have more than one domain for your website, it could hurt your search engine rankings as most search engines can't tell if the domains are the same web page. While you can redirect using the
HTML Code:
<meta http-equiv="refresh" content="5;url=h++p;//example.com/" />
tag to redirect, a better way is to use Apache's .htaccess.
On my website I have 4 domains each working with or without the www . so that is 8 ways to access the page. That would mean each page would have to compete in the search engine with itself 7 times (or for the smarter search engines 3 times). My .htaccess file is shown below:
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.tonyswebdesign\.com$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.tonyswebdesign\.org$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.tonyswebdesign\.net$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.tonyswebdesign\.co\.uk$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^tonyswebdesign\.net$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^tonyswebdesign\.org$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^tonyswebdesign\.co\.uk$ [NC]
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
If you want to just copy and paste the code and replace my domain with yours, remember to put a \ before any dots.
How it works
The first line in the file
activates apache's mod_rewrite program for redirecting urls.
The first rule of each pair is the condition for testing.
Code:
RewriteCond %{HTTP_HOST} ^www\.tonyswebdesign\.co\.uk$ [NC]
In this example if the HTTP_HOST (the domain) matches the regex
Code:
^www\.tonyswebdesign\.co\.uk$
meaning that it is
Code:
www . tonyswebdesign.co.uk
without anything before (because it starts with ^) or anything after (because it ends with $), the url will be changed.
The slashes in the regex are there beacuse dots have a special meaning and the slash tells apache that the dot is a dot and not a rule.
The [NC] part tells it not to check the case of the host.
The second part of each pair is the actual url rewrite.
Code:
RewriteRule ^(.*)$ h++p://tonyswebdesign.com/$1 [L,R=301]
It is in three parts. The first is RewriteRule, then the url to be changed, then the url to change it to.
In this example it changes any number of anything
to
Code:
h++p://tonyswebdesign.com/$1
where the $ means an earlier part of the rule in brackets (the first one in this case, indicated by the $1).
The L can be ignored for now and the R=301 means it is a 301 redirect (which means permantly moved) so next time the browser/search engine will know to check the new url instead.
Just repeat for each domain you need to rewrite.
Note: not all web hosts allow use of .htaccess files and this will only work on apache (not IIS).