Cloudflare - How to redirect non-www to www URL?

Good afternoon!

I’m experiencing a lot of bot attacks that are overloading my payment gateway, and I was advised to migrate my DNS to Cloudflare. I managed to point the DNS, but I’m having trouble redirecting the URL without “www” to the version with “www”.

My URL is https://www.lojacaos.com.br/

Does anyone know how I can do this?

Hey @gabrieltelesc, how’s it going? Have you already tried the steps below?

If you prefer, check out a community tutorial: Redirect example.com to www.example.com

To redirect the URL without “www” to the version with “www” on Cloudflare, you can create a redirect rule in the Cloudflare dashboard. Here’s a step-by-step guide to solve the issue:

1. Access the Cloudflare dashboard

  • Log in to your Cloudflare account.
  • Click on the domain you want to configure (in this case, lojacaos.com.br).

2. Configure DNS

  • Make sure you have set up an A or CNAME record for the root domain (without “www”).
  • The record for @ (root domain) can point to the same IP or destination as “www”. The important thing is that it’s configured.

3. Create a Page Rule

  • In the Cloudflare side menu, select Rules > Page Rules.
  • Click Create Page Rule.
  • Configure the following rule:
  • URL to be redirected: lojacaos.com.br/*
  • Action: Select Forwarding URL.
  • Redirect Type: Choose 301 (permanent redirect).* Destination URL: https://www.lojacaos.com.br/$1 (the $1 preserves the path and parameters from the original URL).

Save the rule.

Additionally, there may be an issue with the Proxy in Cloudflare:

DISABLE THE CLOUDFLARE PROXY

How to disable the proxy in Cloudflare

ISSUES WITH CYBER ATTACKS
For issues with cyber attacks, there are some actions you can take. See below:

Best practices against cyber attacks

Let me know if it works for you.

Cheers,
Estevão.

If it did, please mark this reply as the solution to help others in the community.