Question

How to redirect www.mydomain.com to a naked domain when using App Platform?

Hi team: I just signed up for App Platform and my app is already running… very impressed!

I went into my domain name provider settings and changed all the nameservers to match Digitalocean’s ns1/ns2/ns3 names servers.

All is well and I can see my webapp at https://mydomain.com. This is exactly what I want (a naked domain).

However, I am not sure if/how it is possible to redirect users to the naked domain if they should visit https://www.mydomain.com. Is it possible with Digitalocean?

My domain provider provides some of these options, but I think it would require that I switch my domain’s name servers back to theirs; I would prefer to keep using Digitalocean’s name servers.

Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

alexdo
Site Moderator
Site Moderator badge
March 26, 2023

Hello @jamescolley

You can setup a CNAME record for the www version of the domain namne. CNAME records define aliases for A records by pointing one domain to another domain instead of to an IP address.

https://docs.digitalocean.com/products/networking/dns/how-to/manage-records/#cname-records

As for the https redirection, the domain will automatically be redirected to HTTPS and there are no changes required from your end.

Hope that this helps!

Try setting DJANGO_ALLOWED_HOSTS environment variable to

127.0.0.1,localhost,mydjangodeploymenturl.ondigitalocean.app,www.mydomain.com,mydomain.com

And ensure you have the below in your settings.py

ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "127.0.0.1,localhost,mydjangodeploymenturl.ondigitalocean.app,www.mydomain.com,mydomain.com").split(",")

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel