1

I have moved a lot of people off one of my servers. Each person had an account using subdomains so urn.example.com urn2.example.com. What I would like to do is set it up so ANY subdomain accessed on the example.com domain is automatically forwarded to the correct subdomain on example.co.uk domain.

So urn.example.com would go to urn.example.co.uk.

I'm not that up on DNS so I don't really know what I am looking for.

I have set up an A Record for *.example.com pointing to the IP address of example.co.uk thinking that "may" work but it hasn't.

EDIT: I have now set up a *.example.com CNAME record pointing to example.co.uk. I am waiting to see if it works.

Skyhawk
  • 14,200
  • 4
  • 53
  • 95
webnoob
  • 465
  • 2
  • 16
  • 35
  • A records are direct pointers from hostname to IP address, try it with a CNAME record, which is an alias pointer where you can do something like you are already trying. – Tim Dec 09 '11 at 14:08
  • @Tim - Made the change, will wait for propagation and see how it goes. Thanks. – webnoob Dec 09 '11 at 14:11
  • Just to clarify I have done this correctly, I have added a record against `example.com` where subdomain is `*`, type is `CNAME` and domain is `example.co.uk.` That correct? – webnoob Dec 09 '11 at 14:27
  • Are you running other services beside HTTP? If not, then what web server are you using? – Mircea Vutcovici Dec 09 '11 at 15:23
  • @Mircea - Sorry I am not sure I follow what you mean. I am running Linux Centos with CPanel / WHM. It is only used as a web server if that is what you mean. – webnoob Dec 09 '11 at 15:27
  • All those virtual hosts have the same IP address? If you do not have SSL enabled hosts, then you can host all of them on one single IP. – Mircea Vutcovici Dec 09 '11 at 16:02
  • @Mircea - They are on different servers as they are VPS's. – webnoob Dec 09 '11 at 16:03
  • Am I just over complicating this ... If I set the domain to forward to another one. Wouldn't the subdomains forward as well? – webnoob Dec 09 '11 at 16:17
  • No, it will not "forward". Each subdomain can have its own IP that is different from the parent domain. – Mircea Vutcovici Dec 09 '11 at 16:35

2 Answers2

3

I don't believe that what you want to do can be done using DNS alone. I'd setup a virtual host for *.example.com which does a 301 (permanant) redirect to the correct example.co.uk url.

stew
  • 9,388
  • 1
  • 30
  • 43
  • Do you know of any documentation / tutorials on doing this? All this stuff is rather new to me. – webnoob Dec 09 '11 at 17:09
2

If I understand correctly, you want to:

*.domain.com > *.domain.co.uk

And have the * host specification match up correctly.

If yes, then I suggest creating *.domain.com and then using Rewrite Rules to do a permanment redirect to the co.uk domain.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ([a-z0-9-]+).domain.com [NC]
RewriteRule ^(.*)$ http://%1.domain.co.uk/$1 [R=301]

This is just a stab at the rewrite rule - it has not been tested. The idea is to catch the sub domain name in back reference and then pass it into your new URL.

jeffatrackaid
  • 4,142
  • 19
  • 22
  • Ok, thats a sound idea. Can you just clarify what you mean about "create a *.domain.com". Do you mean host domain.com somewhere and just rewrite everthing then forward? – webnoob Dec 09 '11 at 17:37
  • *.domain.com is just a wild card domain name. This is required so the same domain will answer for all sub domains. – jeffatrackaid Dec 11 '11 at 15:22