htaccess Redirect Subdomain To Main Domain

Bump.. Does anyone know something?
 
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.
 
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:
Did you have content on all of these domains, links built? What is the actual problem you have?
 
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.

I think, I will go with the technician option.

You have 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.

LOL...

Ok! Have a nice sleep!
 
I think, I will go with the technician option.



LOL...

Ok! Have a nice sleep!
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.
 
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.

I will try to work on it. Thanks.
 
Did you have content on all of these domains, links built? What is the actual problem you have?

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.
 
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
 
Last edited:
Back
Top