简体   繁体   中英

how to redirect subdomain to main domain using htaccess

I have canada website, have two version of website ca.domainname.com and canada.domainname.com . I want 301 permenant rediret ca.domainname.com all website to canada.domainname.com through htaccess.tried below code

RewriteCond %{HTTP_HOST} ^CA\.domainmae\.com$   [NC]
RewriteRule ^ http://canada.domainmae.com  [L,R]

Changing

RewriteCond %{HTTP_HOST} ^CA\.domainmae\.com$   [NC]
RewriteRule ^ http://canada.domainmae.com  [L,R]

to

RewriteRule ^(.*) http://canada.domainmae.com  [L,R=301] 

should work. Put that in the htaccess file in te root folder of ca.domainmae.com

If you want to be redirected to the corresponding url on the new website you can use:

RewriteRule ^(.*) http://canada.domainmae.com/$1  [L,R=301]  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM