Full site redirect to subdomain using .htaccess

I have searched all over the internet, I find several answers for getting a redirect, but none of them was 100% complete proof. I need to redirect the .htaccess subdomain that works in every case :

  • ": //mysite.com/" → "Protocol: //subdomain.mysite.com/"
  • ": //www.mysite.com/" → "Protocol: //subdomain.mysite.com/"
  • ": //mysite.com/folder/" → "Protocol: //subdomain.mysite.com/folder/"
  • ": //www.mysite.com/folder/" → "Protocol: //subdomain.mysite.com/folder/"

I know it's possible, but I can't find any good documentation on it, let alone documentation on the basics of .htaccess.

+3


source to share


1 answer


Try this (by putting as the first rule in the .htaccess Rewrite section

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

      

note remember to change both subdomain.yourdomain.com to your desired subdomain url and restart apache.

note 2 Change to https: // if your desired destination is also an https domain



note 3 for TEMPORARY redirects, change "R = 301" to "R = 302"

EDIT some helpful links about apache.htaccess

http://www.tecmint.com/apache-htaccess-tricks/ http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

+1


source







All Articles