I have a website where any request to the non-www domain i.e. http://example.com
is redirected (with status 301) to http://www.example.com
by the server.
If I'm using Django's sites
framework, should I set the domain as example.com
or www.example.com
? All the documents that I've seen always refer to domain as example.com
. I'm confused if the sites framework refers to domain as the full qualified domain name
or just the domain name
. Django docs define domain as "The domain name associated with the Web site". This makes me think it should be without the www part. But this breaks the sitemap (Django generates all URLs without www).
The PREPEND_WWW
settings is another reason for the confusion. It appears as if Django wants you to just define the domain as example.com
and then use this setting to prepend www
.
It should be
www.example.com
, as that is the canonical url of your site. Django uses the domain amongst other things to construct fully qualified URL's, and you'll want these to point towww.example.com
.PREPEND_WWW
is a setting to return a redirect if the user visitsexample.com
instead ofwww.example.com
. It sounds like you got this covered in your webserver. It doesn't affect the domain in any other way.Many sites don't use
www
nowadays (e.g. www.stackoverflow.com redirects to stackoverflow.com), that's the only reason why the documentation often usesexample.com
.