Skip to content
Visit Pages on GitHub
Set theme to dark (⇧+D)


Creating redirects

To use redirects on Cloudflare Pages, declare your redirects in a _redirects plain text file in the output folder of your project. The build output folder is project-specific so the _redirects file should not always be in the root directory of the repository. Changes to redirects will be updated to your website at build time so make sure you commit and push the file to trigger a new build each time you update redirects.

Only one redirect can be defined per line and must follow this format:

[source] [destination] [code?]

A complete example with multiple redirects may look like the following:

/home301 / 301
/home302 / 302
/querystrings /?query=string 301
/trailing /trailing/ 301
/notrailing/ /nottrailing 301
/products/:code/:name /products?code=:code&name=:name

A project is limited to 100 total redirects. Each redirect declaration has a 1000-character limit. Malformed definitions are ignored. If there are multiple redirects for the same source path, the topmost redirect is applied.

Cloudflare currently offers limited support for advanced redirects. More support will be added in the future.

Redirects (301, 302, 303, 307, 308)Yes/home / 301302 is used as the default status code
Rewrites (other status codes)No/blog/* /blog/404.html 404
SplatsYes/blog/* /blog/:splatSee Splats
PlaceholdersYes/blog/:year/:month/:date/:slug /news/:year/:month/:date/:slugSee Placeholders
Query ParametersNo/shop id=:id /blog/:id 301
ForceYes/pagethatexists /otherpageRedirects are always followed, regardless of whether or not an asset matches the incoming request
ProxyingNo/blog/* 200
Domain-level* 301
Redirect by country or languageNo/ /us 302 Country=us
Redirect by cookieNo/\* /preview/:splat 302 Cookie=preview


Redirects execute before headers, so in the case of a request matching rules in both files, the redirect will win out.


On matching, a splat (asterisk, *) will greedily match all characters. You may only include a single splat in the URL.

The matched value can be used in the redirect location with :splat.


A placeholder can be defined with :placeholder_name. A colon indicates the start of a placeholder, and the name that follows may be composed of alphanumeric characters and underscores, :\w+. A placeholder with any given name can only be used once in the URL. Placeholders match all characters apart from the delimiter, which: when part of the host, is a period or a forward-slash; and when part of the path, is a forward-slash.

Similarly, the matched value can be used in the redirect location with :placeholder_name.