301 redirects on Cloudflare Pages: how not to lose visits when you change URLs
Learn how to create 301 redirects with the Cloudflare Pages _redirects file, with syntax, real limits and common mistakes so you don't lose rankings.
You rename your website's services page to make it clearer. The next day, a customer messages you on WhatsApp: “I get a 404 error on the link you sent me.” That link is still in your ads, on your Google profile and in the welcome email.
Changing a URL without warning means losing visits you already earned or paid for. The fix fits in one line of text.
What is a 301 redirect and why does it matter?
It is a server instruction that sends anyone requesting an old address to the new one, and tells them the change is permanent. According to Google Search Central's documentation, Googlebot follows a permanent redirect and the indexing process takes it as a signal that the destination should be the canonical URL. Google also follows a temporary one, but does not treat the destination as canonical.
That is why 301 is the right choice when the change is permanent: you renamed a page, merged two or changed domains. If you are coming from another host, see the guide to migrating from WordPress to Cloudflare Pages without losing SEO.

How do you create redirects on Cloudflare Pages?
With a text file called _redirects, with no extension, placed in your project's static files directory. Cloudflare's documentation says that, if you use a framework such as Astro, it goes in public/. Each line follows this format: source, destination and, optionally, the code.
# Una página renombrada
/servicios-antiguos /servicios/ 301
# Una sección completa
/promo/* /ofertas/:splat 301
Lines that start with # are comments, and lines that don't follow the format are ignored. The file is not shown to the public as just another resource.
What is the difference between status codes?
Cloudflare Pages accepts five codes, and the one you use determines how Google interprets it. If you omit the code, the default is 302.
| Code | Type | When to use it |
|---|---|---|
| 301 | Permanent | Page renamed, moved or merged |
| 308 | Permanent | Permanent alternative to 301 |
| 302 | Temporary | Short-term change, such as maintenance (this is the default) |
| 303 | Temporary | Changes that should not be taken as permanent |
| 307 | Temporary | Temporary alternative to 302 |
Common mistake: writing
/viejo /nuevowithout the 301. Cloudflare applies 302 by default, and Google does not take it as a permanent change. Your new URL may take longer to take the old one's place in the results.
How do I redirect many pages at once?
With an asterisk (splat) for whole paths or with placeholders for specific parts of the URL. According to Cloudflare, you can use only one splat per URL, which captures all characters and is reused in the destination as :splat. Placeholders are written as :name, match everything except the forward slash, and each name can be referenced only once in the destination.
A good practice is to map one by one the pages with traffic or inbound links, and leave the splat for whole sections. Before launching, check in Search Console which URLs were getting visits, as we explain in the Search Console and sitemap guide.

What limits and priority rules does _redirects have?
It supports 2,000 static and 100 dynamic redirects, for a total of 2,100, and each line can be up to 1,000 characters long. If you need more, Cloudflare recommends its Bulk Redirects. These rules avoid surprises:
- For the same source, the rule that appears higher up applies. Write static ones before dynamic ones.
- A redirect is always followed, even if a file exists at that path.
- Redirects run before the
_headersfile. We explain it in the guide to the _headers file. - There is no matching on query parameters, or by country, language or cookie, nor domain-level redirects.
- They do not apply to requests handled by Pages Functions.
Heads up: a redirect wins even over a real file. If you leave an old rule and later create a page at that path, nobody will see the new page.
How do I check that it works?
Open the old address in your browser and confirm it lands on the new one; then check the status code in the Network tab. Also test the splat paths and one of each type of rule. If your domain goes through Cloudflare, also review the SSL/TLS guide.
Server-side redirects are the ones Google interprets most reliably. JavaScript ones are a last resort, because if rendering fails Google may not see them.
In short
That broken link in your ads and on your Google profile gets fixed with one line. Always write the 301 code for permanent changes, order your rules and test before launching. If you would like us to set it up and test it on your site, check out our hosting and domains service.
Frequently asked questions
Where does the _redirects file go in an Astro project?
In the public/ folder, with no extension. Cloudflare Pages reads it when publishing and does not serve it as just another static file.
What status code does Cloudflare Pages use if I don't write one?
302, which is a temporary redirect. For a permanent change you must write 301 at the end of the line.
How many redirects does _redirects support?
According to Cloudflare's documentation, 2,000 static and 100 dynamic, for a total of 2,100. Each declaration can be up to 1,000 characters long.
When do I use 301 and when 302?
301 when you are sure the change won't be reverted. 302 for temporary situations, such as a page under maintenance. Google treats 301 as a signal that the destination should be the canonical URL.
Can I redirect by country or URL parameters?
Not with _redirects. Cloudflare's documentation says it does not support matching on query parameters, or redirects by country, language or cookie.
Do not stop at the theory: apply it to your business
We implement hosting and domains end to end, with your real operation. The first conversation is free.




