Rename a page, reorganise your site or move from another platform, and old links start returning “not found”. On Cloudflare Pages, the fix is a plain text file called _redirects that tells Cloudflare where each old address now lives. This tutorial shows you how to set up Cloudflare Pages redirects, the rules that trip people up, and how to check they work.
What you need
- A site deployed on Cloudflare Pages.
- A list of old URLs and where each should go. If you’re moving from WordPress, our WordPress to static site tutorial explains how to collect it.
Create the _redirects file
- Create a file named
_redirects, with no file extension. - Put it where it ends up in your build output folder, the folder Pages publishes. Most static site generators copy files from a
staticorpublicfolder into the output; check yours does. - Add one rule per line: the old path, the new path or URL, and optionally a status code.
- Commit and push. The rules take effect with the next deployment.
The format
# old path new path or URL code
/old-post/ /new-post/ 301
/about-us /about/ 301
/twitter https://x.com/yourname 302
- Source: a path on your site, starting with
/. - Destination: a path or a full URL, including other websites.
- Code: 301 (permanent), 302 (temporary, the default if you leave it out), 303, 307 or 308.
- Lines starting with
#are comments.
For renamed or moved pages, always write 301. It tells search engines to pass the old page’s rankings to the new one.
Wildcards and placeholders
For whole sections, a wildcard saves writing hundreds of lines:
/blog/* /articles/:splat 301
/news/:year/:slug /articles/:slug 301
- Splat:
*matches everything after that point, and:splatputs it into the destination./blog/hellobecomes/articles/hello. Only one*per rule. - Placeholders:
:namematches one part of the path between slashes, and you can reuse it in the destination.
The rules that trip people up
Order matters. If two rules match the same path, the one nearest the top wins. Put exact rules before broad wildcard rules, or a wildcard can swallow URLs you meant to send somewhere specific.
There are limits. A _redirects file can hold 2,000 static redirects and 100 dynamic ones (rules with * or placeholders), and each line can be up to 1,000 characters. Rules past the limits are ignored silently. Put static rules first: dynamic rules count against the smaller limit. For more than that, use Cloudflare’s Bulk Redirects.
Paths only, not domains. You can’t redirect www.example.com to example.com in this file. Use Bulk Redirects for that; our guide to adding a custom domain to Cloudflare Pages covers it.
Functions win. If you use Pages Functions, requests they handle don’t go through _redirects, even when a rule matches.
Generate the file instead of typing it
If you’re moving dozens of pages, don’t write the rules by hand. Put old and new paths in two columns of a spreadsheet, add a third column with 301, and export it as text with spaces between the columns. If your site is built by a script or a static site generator, it can usually write _redirects for you from a list of old URLs stored with each page, so new redirects are added automatically.
Test your redirects
Open your site’s preview address and visit a few old URLs in a private browser window: each should land on the right page. For an exact check, use curl in a terminal:
curl -I https://your-site.pages.dev/old-post/
Look for 301 (or the code you chose) on the first line and the new address after location:. Test at least one rule from each wildcard, and a URL that shouldn’t redirect, to make sure nothing catches too much.
New to Pages? Start with hosting a static site on Cloudflare Pages.
FAQ
Should I use 301 or 302?
Use 301 for a permanent move, such as a renamed post or a new URL structure: it tells search engines to move rankings to the new address. Use 302 only for temporary changes. If you leave the code out, Cloudflare uses 302.
Can I redirect www to my main domain in _redirects?
No. The _redirects file only matches paths, not domains. Use Cloudflare's Bulk Redirects for domain-level redirects such as www to the root domain.



