2

I am unable to find the proper setup of DNS records with URL Redirect service for a basic web server where:

  • Any URL with www.Example.com should go to server with IPv4 address 192.0.2.4
  • Any URL for example.com or Example.com should be replaced with a URL of www.Example.com.
    • I do not really understand forwarding versus redirecting. What I want is to transform any "example.com" request to a "www.Example.com" request (always using the 'www', and not respecting the naked 'example.com').
  • No other services rendered on this server except the web server (and ping etc.). So no concern about email servers, FTP servers, etc.
  • Sites will be accessed over HTTPS, hence with certificates.

Should it be:

  • Type: A Record
    • Host: @
    • Value: 192.0.2.4
    • TTL: Automatic
  • Type: CNAME Record
    • Host: www
    • Value: example.com
    • TTL: Automatic
  • Type: URL Redirect Record
    • Host: @
    • Value: http://www.Example.com/ Unmasked
2
  • 1
    DNS does not forward or redirect. It only ties the domain name with an IP address and a few associated records.
    – closetnoc
    Commented Oct 21, 2017 at 2:27
  • 1
    @closetnoc Well, yes, you are correct technically. But many DNS services also provide a URL Redirect service along with the DNS records. I edited to clarify. Commented Oct 21, 2017 at 4:09

2 Answers 2

4

You want an A record on host www pointing at your IP address. That will take care of www.example.com.

For example.com -> www.example.com you need a redirect. As noted in the comments, DNS on its own cannot redirect, but many DNS providers offer some sort of redirection service. The capabilities of these will vary a bit between providers. You may be able to setup a redirect on host @ to www.example.com, which would do what you want. However, your provider may not allow you to have this in addition to the www.example.com A record (i.e. you might only be able to redirect the whole domain). In this case you would need to set an A record and handle the redirect yourself (how to do this will depend on what web server you are using - see this question for an example of how to do it with Apache).

Also note that domains are case insensitive. There is no difference between www.example.com and www.Example.com, so you can't redirect from one to the other. Browsers will usually display them as lowercase.

2

There is no such thing as a "URL redirect record" in DNS. To redirect a domain, you need enter the IP address of a web server that is configured to issue an HTTP redirect.

I would take the approach of putting the same IP address for both your apex record and your www record:

  • .example.com A 192.0.2.4
  • www.example.com A 192.0.2.4

Then on your webserver you can set up a virtual host that does the redirect and one that serves content:

<VirtualHost *:80>
    ServerName www.example.com
    redirect permanent / http://example.com/
</VirtualHost>
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/www/example.com"
    ....
</VirtualHost>

Many web hosts don't allow you to edit your own virtual host files. Those hosts typically have the bare domain and the www domain set up to be handled in the same virtual host. In that case, you can just use some .htaccess rules to do the redirects

RewriteEngine On
RewriteCond %{HTTP_HOST} !=example.com [NC]
RewriteRule ^(.*) http://example.com/$1 [NS,L,R=permanent]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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