Last updated on July 26, 2010. Tags: 301 redirect, htaccess, permanent redirection, subdomain
The 301 redirect using .htaccess is not only between two different domains, you can also use it to setup redirection between a domain and a subdomain as well as between two subdomains.
Suppose you have a subdomain website sub.domain.com and you decided to avail a new domain and hosting for this site, say www.domain2.com. When you access the subdomain files in your file manager, it is structured similar to a folder or subdirectory i.e., for the file manager, it is actually www.domain.com/sub/. You can place a .htaccess file in the www.domain.com/sub/ and encode something like:
redirect 301 / http://www.domain2.com/
The 301 redirect recognizes subdomains as separate websites. It will not redirect you to www.domain2.com/subdomain/ unlike in the case of regular subdirectories. Instead, it will redirect you to www.domain2.com/ just like redirection between two separate domains.
If you have 301 redirect in the .htaccess located at root directory www.domain.com, it does not affect the subdomain. For example, suppose you have a redirect 301 / http://www.domain2.com/ in the .htaccess at the root directory of www.domain.com, if you have a subdomain sub.domain.com, you will not be redirected to sub.domain2.com. If you need to redirect sub.domain.com, you need have a separate .htaccess file in the subdirectory www.domain.com/sub/ (subdirectory as seen only in the file manager or FTP).
You can also use the .htaccess if you want to redirect from one subdomain to another. Let's say you have sub1.domain.com and sub2.domain.com and you want to redirect from sub1 to sub2. To accomplish this, create an .htaccess file in www.domain.com/sub1/ and insert the following codes:
redirect 301 / http://sub2.domain.com/.
The htaccess 301 redirect is useful because it redirects visitors to the new domain/subdomain when they visited the old domain/subdomain through search engines, links or typing directly to the address bar. It also transmits backlinks and page rank from the old domain or subdomain. To know more about the basic principles of htaccess 301 redirect, visit this previous article: Using 301 redirect in htaccess file.
Posted by Greten on April 25, 2009 under Server Configuration
Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.
* Required. Your email will never be displayed in public.
Posted by Rajesh on 12.13.09 11:20 am
i want to 301 redirect my page http://business.vsnl.com/matchmakers/index.html to
http://thangavelmatch.com
I cannot upload .htaccess to my rootfolder which is business.vsnl.com (they dont allow us).
Now how can i redirect using 301 ?
anyone pls help me. My old website has good website rankings and it is going to expire in 6weeks.
Posted by Greten on 12.15.09 2:09 am
Hi Rajesh
I’m afraid there is no way to implement 301 if you cannot edit the .htaccess. Some web hosting does that but I just don’t get the logic why they’re doing that.
I read somewhere that search engines treat certain configuration of meta refresh in the same way as 301 redirect. You might want to search for it. I’ll also study it in details for one of my future articles.