Forums

Possible issues with naked domains and Flask apps

Hello Guys,

The situation is that I must use a domain without www as primary option for a Flask app. Of course I read your help page about naked domains (https://help.pythonanywhere.com/pages/NakedDomains) but I wanna be sure if I understand everything properly.

I would like to redirect sampledomain.com without www by utilizing an A record, then redirect the www version with CNAME. The Flask app of the www version simply redirects the main page and subpages to the non www version with a 301 redirect. (I do believe this solution won't hurt my rankings from SEO view point as there are no dupe sites. )

So the question is, can this solution lead to any issues with your "system"? Or the non www version will work exactly the same way as recommended www versions?

That sounds like you're just creating a redirect loop. If sampledomain.com goes to www.sampledomain.com and www.sampledomain.com goes to sampledomain.com, then you'll just keep going round in circles redirecting between them.

Oh, I meant that I would like to use the app on the non www version. So the non www wouldn't be redirected. The redirect would be implemented only for the www app. Is this ok?

You can if you really want to, but we strongly recommend against it. To use the non-www version of the site as your "official" one, you would need to create an A record with an explicit IP address pointing to our server -- specifically, the IP address corresponding to the webapp-XXXXX.eu.pythonanywhere.com hostname that is on the "Web" page. This is because you cannot create CNAMEs for the version of your domain without the www. If you use an A record with an IP address, then if we have to change the IP address for some reason -- for example, if it gets blocked in some countries, or if there's a DoS attack against it, then your site will be down until you have logged into your domain registrar's site and changed your A record. If you use the www version as the official site, you won't have that problem, because you will be using a CNAME and we can change the IP address from our side without you needing to do anything.

There's more information on this help page.