The procedure and steps listed below are addressed to Website Owners and Webmasters who would like to implement a Redirect 301 from a sub-domain to its main domain. This would require suitable modifications on their part to conform with the source code language they may have utilized in the creation of their website and its associated subdomain. This requirement would usually arise when over a period of time they may have found the subdomain to be irrelevant and require it to be removed.
I have been involved with my hobby in website development and design since 2006 and it has been an interesting journey. I have three websites; the oldest on investment management, the second one on philosophy and the youngest one I call the holding website.
In 2008 there was this new wave with regard to mobile websites; and I decided to launch my investment website into the mobile space via a suitable sub-domain. So, content which was available on the main website was copy pasted to a mobile subdomain to enable its viewing on mobile and other WAP devices. With my involvement with my main work as an investor and spare time applied in the development of the three websites, the mobile sub-domain got left behind along the way; and more recently I observed that there were more visitors coming to my main domain via mobile devices as a segment than were coming to the mobile sub-domain (where most visitors were visiting via their PCs and laptops).
During a extensive review I conducted in end 2011 on matters virtual world and my websites, I realized that the mobile sub-domain was unnecessary to maintain and continue; but it had a few page one results to its credit. So, to redirect or remove the sub-domain via the server end would be easy; however, there would have been a loss of these page one results. You see if the sub-domain were to give an error 404 instead of the required redirect 301 I would lose the page one search results.
I searched the web, seeking information on the "how to" of doing this redirect 301 and subsequent removal of the mobile sub-domain without losing the page one results. I did come across a couple of videos by Matt Cutts on matters Canonical and Redirect 301, but they were only indicative. There were other resources available as well, but I was unable to gain a complete understanding of the steps required to accomplish this task from any one source.
So, here I was with a mission to remove my mobile sub-domain without a loss of any of the page one results. The tools at hand were the little information available on the matter and my own understanding of how this matter could be best addressed and resolved. Described below are the steps I have taken to enable a successful Redirect 301.
Canonical: The first step was to canonical all the webpages of the sub-domain to advise the search engines with regard to my preference to the main domain as far as the search results were concerned. This was simple as it requires the inclusion of a page level Meta tag in the head section. This required a link rel="canonical" pointing to a href to the original webpage on the main domain. So, each webpage on the sub-domain has this canonical Meta tag which gave the name of the original webpage on the main domain which I preferred.
<link rel="canonical" href="https://www.domain.com/webpage.html">
After completing this task, all appeared to be well. However, on closer observation I realized that the mobile sub-domain from "sub-domain.domain.com" had transformed into a "www.domain.com/sub-domain"; and the content was still that of the sub-domain. Anyhow the search engines had been informed with regard to my preference to the main domain.
Redirect 301: The next step was a bit tricky, as the mobile sub-domain was source coded in "php"; anyhow by this stage I had finally decided that it would be a good idea to go for a webpage level Redirect 301 from the mobile sub-domain to the main domain. This required the implementation of the redirect 301 instruction on the webpages themselves to point towards its original webpage on the main domain:
header( "https/1.1 301 Moved Permanently" );
header( "Location: https://www.domain.com/webpage.htm" );
Of course, the content of the webpages of the subdomain themselves were removed while leaving only the code shown above. You may be required to apply other directives, if you have utilized another source code language.
All appeared to be functioning well, and both the "subdomain.domain.com" and the "www.domain.com/sub-domain" were redirecting seamlessly to the original webpages on the main domain without any time delay. Now, on closer observation it came to light that the subdomain's sitemap.xml, feed.xml and robot.txt were in error.
.htaccess file: To resolve this issue, I applied a redirect 301 instruction for the sitemap.xml, feed.xml and robot.txt files via the .htaccess file; applying the following:
Redirect 301 /robots.txt https://www.domain.com/robots.txt
Redirect 301 /sub-domain/robots.txt https://www.domain.com/robots.txt
Redirect 301 /feed.xml https://www. domain.com/feed.xml
Redirect 301 / sub-domain /feed.xml https://www. domain.com/feed.xml
Redirect 301 /sitemap.xml https://www. domain.com/sitemap.xml
Redirect 301 / sub-domain /sitemap.xml https://www. domain.com/sitemap.xml
This resulted in the feed.xml and sitemap.xml defaulting to the main domain seamlessly. But, the robot.txt file was still showing up.
robot.txt: So, to put the robot.txt file of the subdomain to rest, I applied the following to it and uploaded it to the server's subdomain folder:
Analytics, Webmaster Tools and AdSense: It would go without saying that a careful watch was kept on the progress of this matter via the webmaster tools resources available at Google and Bing. Of course, it would appear that Yahoo no longer supports the webmaster function for reasons best known to them; and directs you across to Bing for further action. Of course, action was required to be taken at Google Webmaster Tools, Google Analytics, Google AdSense and Bing Webmaster Tools. By now the page one search results pertaining to the mobile subdomain had also defaulted to the original webpages of the main domain.
After the redirect 301 had been implemented on the sub-domain; I monitored its Google Analytics profile to observe and confirm that the traffic had indeed dropped off and gone to zero.
I checked the sitemap.xml at the Webmaster Tools and they were defaulting to the main domain. So, I resubmitted them; and on the next update the sitemap.xml of the sub-domain was defaulting to the sitemap.xml of the main domain. I waited a few days for it to be updated as far as the index was concerned. Now the sub-domain was pointing towards the main domain for all practical purposes; and even if any of the webpages of the sub-domain were typed into the browser it would seamlessly redirect 301 to the original webpage on the main domain. Of course, I also checked a few webpages of the sub-domain in my browsers (IE9 and Chrome) to confirm that they were indeed seamlessly defaulting to the original webpage on the main domain. I also checked the sitemap.xml, feed.xml and robot.txt to reconfirm that they were indeed defaulting to the main domain.
After waiting a few days, I deactivated the AdSense ad unit pertaining to the sub-domain, as well as all URLs of the sub-domain. Next I went ahead and deleted the Google Analytics profile of the sub-domain. After a few more days I deleted the Google Webmaster Tools and Bing Webmaster Tools profiles pertaining to the sub-domain. It took a few more days before I went ahead and removed the sub-domain URLs and ad unit from Google AdSense.
Next Steps: The next step would be to provide a webpage level Redirect 301 via the .htaccess file and remove the webpages themselves; this would be implemented in the next few days. If this action is successful, then it would save a lot of server space which I would utilize towards the further development of the main domain.
There would be a matter of the links on other sites and back links I myself may have created on social networking sites or social book marking sites over the passage of time to the subdomain's homepage URL; and I may not be able to inform other website owners to remove such links or remove the links I myself may have placed as the answers may have been archives. Despite this additional link in the virtual world, I would not be too concerned about it as it would be a Redirect 301 to the homepage of the main domain.
The above is with a view to help remove inadvertent duplication even if well intended as was the case with regard to my mobile subdomain. And to put matters into perspective, it would probably be a better idea to go with mobile apps as far as the mobile vertical is concerned. But, that would be a completely separate matter and would require an understanding and command over C++ or another relevant higher level language.
Note of caution: Before venturing into this matter of a Redirect 301, the website owner and/or webmaster would be well advised to gain a relevant understanding of the steps required in its correct implementation. In case, of doubt this matter may be referred to a technically qualified person or guide or mentor. This mentor is expected to firstly explain the theory and then guide you through the various steps of correct implementation. Further, you as the website owner and webmaster would be able to draw upon the mentor's experiences and avoid the common errors you may otherwise commit.
The Redirect 301 implementation described above in itself is safe if you were to be realistic in your expectations and have done the initial preparation. Further, patience would be required as the whole process may take upto 3 months to complete.