Redirecting Pesky Subdomains

I often develop websites on a development subdomain before making them live, especially with website redesigns. This gives us a chance to review the info, develop a great site and test the site prior to making it live. In addition, we use hosting companies for many of our sites, such as BlueHost, that allow multiple sites one one account. With this, they require a subdomain entry for each new add-on domain in Cpanel when we are using one hosting account with multiple sub-directories / add-on sites.

For example, we will create a site on “newsite.durangowebdevelopment.com” which points to a subdirectory of the primary durangowebdevelopment.com domain (e.g. public_html/newsite). This helps us cut hosting costs for our customers as well as allows us to develop the website in the background if the customer has an existing site prior to making the redesign live.

The Problem:

This can be a real SEO killer if you allow those additional subdomains to stay live because Google (etc.) will see these as 2 separate domains pointing to the same content.

What makes this harder, is that we have a variety of pages inside the site that we want all of the links to remain. For example, we have “newsite.durangowebdevelopment.com/about-us” and we want that to correctly point to “newsite.com/about-us” to make sure any indexed pages are correctly 301 redirected.

The Solution:

We can add a bit of code to the .htaccess file which tells the server to redirect these links.¬†There are a lot of resources on the web about the .htaccess file and I searched for hours to what find what I thought should be a simple solution. Via a combination of posts, resources, etc., I finally found one that worked for me. I don’t claim to be an expert at writing code so, as always, back up your .htaccess file and proceed at your own risk.¬† However, this has worked beautifully for me… Simply add this snippet to your file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^newsite\.durangowebdevelopment\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.newsite\.durangowebdevelopment\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.newsite\.com\/$1" [R=301,L]

Viola! Any page links that are still hanging around in web space will now redirect to the correct domain! Hope it helps…