Wednesday , 26 April 2017
Home » .htaccess » [.htaccess] 301 Redirect Subdomain to Main Domain
[.htaccess] 301 Redirect Subdomain to Main Domain

[.htaccess] 301 Redirect Subdomain to Main Domain

Hello Friends,

I have a WordPress multisites and I was using sub domains for each site. Now I decided to combine all subdomain to main domain. For that, I need to write 301 redirect subdomain to main domain in order to keep the SEO benifits and avoid broken links. Its simple to redirect sub domain to domain pages. Look at below rules.

Case 1: If you have WordPress multi site set up or wild card sub domain and have main domain .htaccess. Write below code in main domain’s .htaccess file for sub domain to domain 301 redirection.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.phpfreelancedevelopers.com$
RewriteRule ^$ http://phpfreelancedevelopers.com/pathtotest/ [R=301,L]
RewriteCond %{HTTP_HOST} ^test.hotactresses.in$
RewriteRule ^(.*)$ http://phpfreelancedevelopers.com/$1 [R=301,L]

Case 2: If you have sub domain created, than write below code in sub domain’s .htaccess.

RewriteEngine On
Redirect 301 / http://phpfreelancedevelopers.com/

Isn’t it easy. 301 redirect sub domain to domain. If you face any problem in writing 301 redirection for sub domain to root domain than comment below and I will respond as soon as possible.

      
Plugin by: PHP Freelancer

About Rakshit Patel

I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I have developed this site to share my knowledge, thoughts and experience during the development of projects. We are group of developers working together. If you want to hire us for any PHP related work, you can reach me via Email, Phone or Chat.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.