Brian Moreau

Search this website


Plasma
Home
|
Solutions
|
Portfolio
|
Articles
|
Projects
|
Photography
|
Technology news
|
Blog
|
Contact
 
 
 

Advance website design tips:

.htaccess URL redirection on shared servers with multiple domains or directories.

This is a problem that challenged me for some time and took me literally hours of online searching to find an effective solution.
It was also the cause of some very strange page indexing by search engines which was affecting my page rank.

The problem

On any server you can create subdirectories, for hosting multiple domain names then you will put each domain in its own sub directory.
That directory will be available using two methods.

www.subdomainname/mytopdomainname.com/
www.mytopdomainname/subdomainname.com/

The problem with this it can allow people to browse your directories and it also allows search engine bots to index your website incorrectly.
For example the page home.htm on subdomain.com can be indexed as up to four different pages thus.

www.subdomainname/mytopdomainname.com/home.htm
www.mytopdomainname/subdomainname/home.htm
www.subdomain.com/home.htm
subdomain.com/home.htm

Also your site will look much more professional if the correct and full domain name is shown in the URL

The solution
This solution redirects the following URL’s to www.brianmoreau.com in subdirectory brianmoreau on domain wfiuk.com

# force URL = wwww.brianmoreau.com
# brianmoreau.co.uk
# brianmoreau.com
# brianmoreau.wfiuk.com
# www.brianmoreau.wfiuk.com
# wfiuk.com/brianmoreau

The code
Options -Indexes
DirectoryIndex index.html index.php home.php home.htm
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. brianmoreau\.com$ [NC]
RewriteRule ^(.*)$ http://www. brianmoreau.com/$1 [R=301,L]

Notes
The above code will also redirect brianmoreau.co.uk to brianmoreau.com providing you have both as sub domains or add-on domains on your top level domain.
Obviously you can’t redirect a domain you don’t own.

To redirect .co.uk only use
RewriteCond %{HTTP_HOST} !^www\. brianmoreau\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www. brianmoreau.co.uk/$1 [R=301,L]

This rewrite rule has been tested for passing of variables in the URL in the following format.
URL?abc=123&cde=456

Please note this may not work on all servers and may depend on your individual server configuration. I strongly advise you make a backup copy of your .htaccess file before you modify it.
 
The example above was tested successfully on hostgator.com

 

 
 
.htaccess URL redirection
© 2012 Brian Moreau