Cloudflare pages - domain related problem
I bought a domain on hostinger. I deployed my site on cloudflare pages. However, I have one problem. My domain works fine when I access it without typing “www”. When I enter the domain with “www” the site does not work. How can I make a redirect on for the domain with www so that it directs me to the domain without “www”?
I followed instructions so I changed dns to cloudflare dns
1 Reply
Support AI
According to the Cloudflare documentation, you can set up a redirect to forward traffic from your domain with "www" to the domain without "www" using Redirect rules.
First, make sure that your domain has a proxied DNS A or CNAME record that properly resolves DNS queries. You may also want to include a record for the "www" subdomain.
Then, you can create a Redirect rule to forward traffic from your domain with "www" to the domain without "www". You can do this by following these steps:
1. Go to the Cloudflare dashboard and select the domain you want to set up the redirect for.
2. Click on the "Rules" tab and then click on "URL Forwarding".
3. Click on "Create URL Forwarding Rule".
4. In the "When incoming requests match" section, select "Equals" as the operator and enter "www.yourdomain.com" as the value.
5. In the "Then" section, select "Forward URL" and enter "https://yourdomain.com" as the target URL.
6. Make sure to enable "Preserve query string" and set the status code to "301".
7. Click "Save and Deploy" to save the rule.
This will redirect all requests for "www.yourdomain.com" to "yourdomain.com", keeping the original path and query string.
For more information, you can refer to the Cloudflare documentation on URL Forwarding: https://developers.cloudflare.com/rules/url-forwarding/
Also, you can use the Expression Editor to enter the following expression:
(http.host eq "www.yourdomain.com")
to match the incoming requests.
Please note that you should replace "yourdomain.com" with your actual domain name.Sources
This is an AI generated response, it may not be 100% accurate. Please validate the output. You can ask followups by replying to this message or mentioning me.