how to redirect subdomain to root domain?

Discussion in 'Web Design' started by thashytt, Jun 30, 2016.

  1. thashytt

    thashytt Registered Member

    Joined:
    Feb 24, 2015
    Messages:
    85
    Likes Received:
    14
    Hello,

    So i recently purchased an expired domain and many of its links are pointed to a subdomain. I cant seem to figure out how to 301 redirect through .htaccess - anyone can help me out it would be greatly appreciated.


    For example this is my goal:

    subdomain.domain.com/post1 -->>> domain.com/post1
    subdomain.domain.com/post2 -->>> domain.com/post2

    and so forth.

    Do i need to set back up the subdomain in DNS before i try to 301 through htaccess?
     
  2. cloaking

    cloaking Registered Member

    Joined:
    Aug 21, 2015
    Messages:
    94
    Likes Received:
    31
    I haven't tested it, but this .htaccess code should do the trick:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$
    RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
    
     
    • Thanks Thanks x 1
  3. ShiinaMashiro

    ShiinaMashiro Junior Member

    Joined:
    Mar 19, 2015
    Messages:
    109
    Likes Received:
    23
    Occupation:
    None
    Location:
    France
    You could manage the dns instead of playing with htaccess.
     
    • Thanks Thanks x 1
  4. mizpress

    mizpress Newbie

    Joined:
    Jun 7, 2015
    Messages:
    21
    Likes Received:
    3
    Gender:
    Male

    Is it a WordPress website?