9000+ different subdomains 301 to main domain, .htacess apache
Posted
by
Karim
on Server Fault
See other posts from Server Fault
or by Karim
Published on 2011-01-05T23:26:58Z
Indexed on
2011/01/06
1:55 UTC
Read the original article
Hit count: 325
I bought a domain that had various subdomains such as
Kim.domain.com/whatever
john.domain.com/whatever1
Lizo.domain.com/whatever2
Simon.domain.com/whatever1
And this was in the thousands, and also had links to these pages
I'd like to do a 301 redirect for all these urls into http://domain.com
Any idea how this could be done?
This is for a apache web server and needs to be done via .htaccess
I have implemented the solution from reading the answer below.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www. domain.com$
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$ http:/ / www. domain.com/$1 [L,R=301]
However I have a slight problem, I would like to redirect all subdomains + subfolders to http://www. domain.com/
With the exception of http: //domain. com/subfolder/, in which case I would like to redirect to http: // www.domain. com/subfolder/ [i.e. exception for no subdomain]
I'm guessing I need to add an exception, what can I do to implement this.
Note: example URLs above have had spaces added to them to prevent spam blocks for blocking the post.
© Server Fault or respective owner