How to Redirect a folder to a Subdomain using .htaccess

January 7th, 2010

If you create a sub domain (e.g. shop.example.com) from cPanel you will find that a subfolder (example.com/shop) in the same name has been added to the directory list. When you upload anything on the folder, it will reflect in the subdomain created. When you visit shop.example.com or example.com/shop, you will see that the content is the same.

There is nothing wrong with it, however from the view point of SEO and Search engines, this creates duplicate content, because… for search engines a folder is different from a subdomain. To avoid this issue we can simply add or edit the .htaccess. This will tell SE’s that the folder has been permanently redirected to the sub domain.

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^folder.example.com
RewriteRule (.*) http://subdomain.example.com/$1 [L,R=301] 

Please change (subdomain, example) as per your website.

Comments

  1. Redirect Main Domain to Sub Domain using .htaccess January 22nd, 2010

    […] Related article: 1. How to Redirect a folder to a Subdomain using .htaccess […]

Leave A Comment