To use redirects on Cloudflare Pages, declare your redirects in a
_redirects plain text file in the output folder of your project. The 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/twitch https://twitch.tv/trailing /trailing/ 301/notrailing/ /nottrailing 301/blog/* https://blog.my.domain/:splat/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 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
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