I have a NodeJS app deployed on Digital Ocean, with a domain attached to it.
The app is hosted under https://www.myapp.com
I would like to redirect https://myapp.com to https://www.myapp.com
However, The DNS is managed by Digital Ocean. I can add records, but the record “name” is automatically pre-fixed with www.myapp.com
.
So how can I achieve this redirect?
Thank you, Klaas
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
I believe that this should be doable as you are already using DigitalOcean for your DNS management:
In this example, we create a middleware that checks if the incoming request’s hostname is
example.com
. If so, it redirects the request towww.example.com
with a 301 redirect status code.Let me know how it goes!
Best,
Bobby