Question

Add www to my url

Posted October 14, 2017 2.1k views
Networking DNS Ubuntu 16.04

How can I add www to my URL?

I followed the instructions for setting a host name here, but whenever I browse for http://www.foo.com, I get redirected to http://foo.com.

How do constantly keep www.foo.com?

I have the following DNS records:

Type Hostname Value TTL (seconds)
CNAME *.foo.com is an alias of www.foo.com. 43200
A foo.com directs to 201.227.660.894 3600
A www.foo.com directs to 201.227.660.894 3600
NS foo.com directs to ns1.digitalocean.com. 1800
NS foo.com directs to ns2.digitalocean.com. 1800
NS foo.com directs to ns3.digitalocean.com. 1800

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

3 answers

You’ll have to verify who’s redirecting your domain. Is there any app running there?

If you use python (and requests library) try this

C:\Users\Alexei>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r = requests.get('http://amdb.com.br')
>>> print r.history
[<Response [301]>]
>>> print r.history[0].headers
{'Content-Length': '178', 'Server': 'nginx', 'Connection': 'keep-alive', 'Location': 'https://www.amdb.com.br/', 'Date': 'Wed, 18 Oct 2017 11:13:34 GMT', 'Content-Type': 'text/html'}

Inspecting all history entries’ headers, you’ll get some hint about who’s redirecting. In this example, nginx itself. I believe your problem isn’t in the DNS, because it doesn’t make redirections. Servers and applications do.

Delete 1st and 3rd entries and add a CNAME value www to server @ (yes, just @)

  • I did as advised and waited more than the required TTL. It didn’t have effect.
    All what is left is:

    Type Hostname Value
    CNMAE www.foo.com is an alias of foo.com
    A foo.com directs to 201.227.660.894
    NS foo.com directs to ns1.digitalocean.com.
    NS foo.com directs to ns2.digitalocean.com.
    NS foo.com directs to ns3.digitalocean.com.

    still get redirected to http://foo.com when I type www.foo.com :\

Submit an Answer