3

I have several A records like so:

Subdomain             IP Address
example.example.com   198.51.100.0
example.com           203.0.113.0

And a CNAME record that looks like this:

Alias              Destination
www.example.com    example.com

I want to make example.com throw a 301 redirect to www.example.com.

So I'd change the last A Record to:

www.example.com       203.0.113.0

And swap the two URLs in the CNAME record to look like the following:

example.com        www.example.com

Question: Is this change going to make example.example.com resolve to 203.0.113.0 instead of to 198.51.100.0?

TRiG
  • 1,167
  • 2
  • 13
  • 30
James
  • 153
  • 2
  • 8
  • 5
    If you just want a HTTP/301 redirect, why not put it at the web server level, instead of monkeying with DNS? – Avery Payne Apr 19 '11 at 22:08
  • To get it right, you mean you're gonna swap `foo.com` into being alias for `www.foo.com`, correct? The last example is a bit confusing. And as *@Avery* said, if you need **301**, then that's not really DNS stuff. – Karol J. Piczak Apr 19 '11 at 22:22
  • Yes, that is correct. I've corrected the question. – James Apr 20 '11 at 14:12

3 Answers3

6

If you have an A record for example.foo.com then no DNS record for any other domain will affect that. So the answer is no.

Other facts to bear in mind:

You can't have a CNAME and an A record for the same fully qualified domain

A CNAME is not he same as a 301 redirect. A CNAME will return the same ip address as the new domain. Your browser will go to that ip asking for the original domain. A 301 redirect will cause your browser to do a DNS lookup for the new domain and then go and ask for the new domain.

ollybee
  • 568
  • 2
  • 10
2

like both of the comments said from avery and karol, you would not want to do this in DNS. there is different ways to do it in different configurations

if you have htaccess:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

a simple google search for 301 redirect will show you a bunch of different ways.

Jeff
  • 1,089
  • 5
  • 25
  • 46
  • I dont think dns will let you have an A and CNAME record for both www.foo.com. i could be wrong though not sure – Jeff Apr 19 '11 at 22:32
  • *@Jeff*, you're right. I think it's just a typo in the question, that's why I asked for verification. – Karol J. Piczak Apr 19 '11 at 22:35
  • Sorry i overlooked that -- I didn't think you could but wasn't 100% sure, i was actually about to test it on my internal dns. thanks – Jeff Apr 19 '11 at 22:53
1

If you want to cause the HTTP server to send an HTTP response with status 301, then do that. Changing DNS entries isn't the way to implement a redirect in your HTTP server.

bignose
  • 942
  • 10
  • 20