I assume you already moved your domain to Cloudflare.
- On the sidebar, click Rules -> Redirect Rules.
- Click Create Rule button.
- Fill the the Rule name whatever you want.
- Choose Custom filter expression
- Follow this configuration:
- Field: Hostname
- Operator: Equals
- Value: example.com
- Type: Dynamic
- Expression: concat("https://www.example.com", http.request.uri.path)
- Status Code: 301
-
Check Preserve query string checkbox
-
Click Save button.