Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 9 '11 at 14:08
    
@Tim - Made the change, will wait for propagation and see how it goes. Thanks. –  webnoob Dec 9 '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 9 '11 at 14:27
    
Are you running other services beside HTTP? If not, then what web server are you using? –  Mircea Vutcovici Dec 9 '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 9 '11 at 15:27
show 4 more comments

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
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 9 '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
add comment

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.

share|improve this answer
    
Do you know of any documentation / tutorials on doing this? All this stuff is rather new to me. –  webnoob Dec 9 '11 at 17:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.