Help! Redirect subdomain to domain

5 replies
  • SEO
  • |
Hello There

I need help with htaccess redirection code. I want to redirect all mail.domain.com/blog (and all internal pages) to www.domain.com/blog.

also mail.domain.com/gift (and all internal pages) to www.domain.com/gift.

I currently have a redirection code which is only redirecting mail.domain.com to www.domain.com. But this is not redirecting some of my subpages like the ones above.

mail subdomain is a virtual domain created by cpanel, so i cannot insert any codes in the root of the subdomain.

Help will be much appreciated.

Thanks
===

current code used

RewriteEngine on
RewriteCond %{http_host} !^www.example.com$ [nc]
RewriteRule ^(.*)$ IANA — Example domains [r=301,nc,L]
#domain #redirect #subdomain
  • Profile picture of the author jo4acause
    Anyone warrior out there who can help?
    {{ DiscussionBoard.errors[4599675].message }}
    • Profile picture of the author patrich
      Try this:

      Code:
      RewriteEngine on 
      RewriteCond %{HTTP_HOST} ^mail.mysite.com$ [NC]  
      RewriteRule ^/?(.*)$ http://www.mysite.com/$1 [R=301,L]
      Make sure you change the "mysite" to your actual domain name. It should work for you.
      Signature

      Professional licensing for a variety of careers now available at License Butler.

      {{ DiscussionBoard.errors[4599715].message }}
  • Profile picture of the author patrich
    Btw, that code needs to go in the .htaccess file on your server.
    Signature

    Professional licensing for a variety of careers now available at License Butler.

    {{ DiscussionBoard.errors[4599724].message }}
  • Profile picture of the author jo4acause
    Thanks Patrich, appreciate your help.

    I will add this code and update.
    {{ DiscussionBoard.errors[4604963].message }}
  • Profile picture of the author jo4acause
    I added it to my root domain but doesn't work. Because mail subdomain is a virtual subdomain created by cpanel there is no option to add it to the root of the subdomain.

    This is how the current Htacess redirection codes are set up.

    ======

    Options +FollowSymlinks
    RewriteEngine on

    RewriteCond %{http_host} !^www.exampple.com$ [nc]
    RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc,L]

    RewriteCond %{HTTP_HOST} ^mail.example.com$ [NC]
    RewriteRule ^/?(.*)$ http://www.example.com/$1 [R=301,L]
    {{ DiscussionBoard.errors[4606362].message }}

Trending Topics