By Aaron
I have currently a problem with the whole domain thing. What i want to achieve is that my app on app platform is accessible from mydomain.com and www.mydomain.com but the root should always redirect to the www subdomain.
What i did before was i added both domains on namecheap and then the app was accessible from root and www. but since i use localstorage in my app that is a problem. and if i just added www and redirected the root to that it was only possible with http://mydomain.com and not https://mydomain.com.
How could i solve this? Would it be easier if i let DO manage my domain (nameserver) and what records would i have to add then
thanks
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!
Accepted Answer
Hi there,
Yes, letting DigitalOcean manage your domain might make the process easier because it allows you to manipulate DNS records directly from their dashboard.
However, regarding the redirect itself from the non-www to the www version of your domain, I don’t think that it is currently natively supported by the App Platform. You could handle the redirect on your the application level rather than the App Platform itself.
Depending on the language and framework you’re using for your app, the method to implement the redirection will differ.
For example, in a Node.js Express app, you could do something like this:
app.use((req, res, next) => {
if (req.hostname === 'mydomain.com') {
return res.redirect(301, `https://www.${req.hostname}${req.originalUrl}`);
}
next();
});
I recently answered a similar question about Django as well.
Feel free to share more details about the framework that you are using and I will be happy to make a suggestion!
The best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.
Hope that helps!
- Bobby.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.