1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

htaccess Redirect Subdomain To Main Domain

Discussion in 'Web Design' started by marios_521, May 29, 2017.

  1. marios_521

    marios_521 Regular Member

    Joined:
    Mar 23, 2013
    Messages:
    398
    Likes Received:
    70
    Gender:
    Male
    Location:
    Europe
  2. marios_521

    marios_521 Regular Member

    Joined:
    Mar 23, 2013
    Messages:
    398
    Likes Received:
    70
    Gender:
    Male
    Location:
    Europe
    Bump.. Does anyone know something?
     
  3. seo_seo_seo

    seo_seo_seo BANNED BANNED

    Joined:
    Mar 24, 2017
    Messages:
    150
    Likes Received:
    37
    This cannot be completed without knowing the full details of the task, e.g. which domains, what type of redirect, www or non-www and a dozen more.
    You should contact a specialist and pay for this as .htaccess is a very powerful tool which can make or break your site.
     
  4. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,478
    Likes Received:
    3,108
    Gender:
    Male
    You have to create a wild card dns entry that points to the same ip, then have the requested host determined either by the serverside script or by htaccess (or similar, depending on what server you are using) and redirect accordingly. Don't tell me to provide a step by step guide please :p I am sleepy and gonna go to bed lol.
     
    Last edited: May 29, 2017
  5. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    649
    Did you have content on all of these domains, links built? What is the actual problem you have?
     
  6. marios_521

    marios_521 Regular Member

    Joined:
    Mar 23, 2013
    Messages:
    398
    Likes Received:
    70
    Gender:
    Male
    Location:
    Europe
    I think, I will go with the technician option.

    LOL...

    Ok! Have a nice sleep!
     
  7. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,478
    Likes Received:
    3,108
    Gender:
    Male
    Jokes apart, research what i said. It is fairly simple to do this. You wont need to hire anyone if you have some server and script experience.
     
    • Thanks Thanks x 1
  8. marios_521

    marios_521 Regular Member

    Joined:
    Mar 23, 2013
    Messages:
    398
    Likes Received:
    70
    Gender:
    Male
    Location:
    Europe
    I will try to work on it. Thanks.
     
  9. marios_521

    marios_521 Regular Member

    Joined:
    Mar 23, 2013
    Messages:
    398
    Likes Received:
    70
    Gender:
    Male
    Location:
    Europe
    No. There is no content on them.
    I bought an expired domain and it has 20 subdomains showing in Majestic, with backlinks pointing to them.

    I want all subdomains like:

    us.domain.com
    uk.domain.com
    eu.domain.com

    redirected to domain.com, for SEO purposes.
     
  10. Gogol

    Gogol Jr. VIP Jr. VIP

    Joined:
    Sep 10, 2010
    Messages:
    3,478
    Likes Received:
    3,108
    Gender:
    Male
    Step 1:

    Go to your Domain Manager and look for the Edit Zone File / DNS entry option.
    Keep in mind that for doing this, you have to keep the name servers be left as default (managed by your domain provider). If you have them pointed to your hosting provider, then you will have to do the following changes in your hosting provider account instead of domain manager.

    Find the IP of your host, let's say it is 12.13.14.15

    Edit/add A records so that it read e.g.

    Hostname : @ (this will also work for the www)
    Ip: 12.13.14.15
    Ttl: 1000

    Hostname: * (this will catch the rest of them, like en.domain.com, cs.domain.com etc, but not the www)
    Ip:12.13.14.15
    Ttl:1000

    Step 2:

    Now, wait for an hour or so, and then go to your hosting account (i am considering that you have already added the domain back to your hosting, and added LAMP stack in it with root to /var/www/html/domain.com/ and you have htaccess rewrites enabled on your server) and edit/add .htaccess file which has the following lines preferably at the beginning:

    Code:
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} es\.domain\.com$ [NC]
    
    RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,L,NE]
    
    RewriteCond %{HTTP_HOST} pt\.domain\.com$ [NC]
    
    RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,L,NE]
    
    
    Basically keep repeating the rewrite condition and rule for each of the sub domain.


    Btw, please backup your existing data. I am writing this from my mobile and this is untested code. So, it might screw up your server. Be prepared. Please do not hold me responsible if something happens :p
     
    • Thanks Thanks x 1
    Last edited: May 30, 2017
  11. marios_521

    marios_521 Regular Member

    Joined:
    Mar 23, 2013
    Messages:
    398
    Likes Received:
    70
    Gender:
    Male
    Location:
    Europe
    Wow! This is a GUIDE! Thanks.