By Nitin
I’ve my website and dns on digitalocean. I want to 301 redirect non-www urls to www urls. Currently I found answers for apache server, but not for cloudflare. Does anyone know how to do it? I don’t want to change nameservers to Cloudflare website.
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!
Hello there,
If I understand this correctly you want the redirection to happen on DigitalOcean’s end and not Cloudflare since you do not want to change your nameservers to CF?
Are you using Apache/Nginx on your server? You can check this tutorial for more information:
Hope that this helps!
Hi @NitinAngler,
I’ll recommend you to not add your 301 redirects on Cloudflare but on your Application.
@alexdo has already provided answers on how to do Nginx and Apache redirect but if you want to do redirect on your App Platform check the following questions:
https://www.digitalocean.com/community/questions/app-platform-how-can-i-redirect-non-www-to-www
https://www.digitalocean.com/community/questions/redirect-non-www-to-www-using-app-platform
Using Cloudflare Rules.
But first, you must make sure that your website has www urls on its settings, if not you will caught on redirect error loop.
In this example the website already using HTTPS (Lets Encrypt) and using Full Encryption Mode and disable Always Use HTTPS on Cloudflare SSL/TLS settings.
mydomain.com/*Forwarding URL301 - Permanent Redirecthttps://www.mydomain.com/$1If you already have another rule, make sure this rule being the first rule
This rule will catch any non-www with http or https request and redirect it into https://www.mydomain.com/, so no need to create Apache/nginx redirection rules
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.