0
votes

I have just deployed my django project on dogitalocean (nginx/ubuntu 16.04) server.

In Allowed hosts I added ['.example.com', 'IP']

In the DNS records of my digitalocean droplet I added two A type records one is pointing example.com to the IP, & the second is pointing www.example.com to the same IP.

Problem is that I visited the site as example.com & logged in as a normal user, & then I opened a new tab (still logged in at example.com) & visited site using www as www.example.com & i'm not logged in there.

How can I redirect example.com to www.example.com? Thank You :)

1

1 Answers

0
votes

Your session cookie is not valid for both domains, that's why you're not logged in when accessing www.example.com.

One way to fix it is to set

SESSION_COOKIE_DOMAIN=".example.com"

in settings.py so the session cookie is valid for example.com and all subdomains.
(note the . preceding the domain name)

See the Django session settings documentation for more information.