To use redirects on Cloudflare Pages, declare your redirects in a plain text file called
_redirects without a file extension, 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/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 2,000 static redirects and 100 dynamic redirects, for a combined total of 2,100 redirects. Each redirect declaration has a 1,000-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||302 is used as the default status code.|
|Rewrites (other status codes)||No|
|Splats||Yes||Refer to Splats.|
|Force||Yes||Redirects are always followed, regardless of whether or not an asset matches the incoming request.|
|Redirect by country or language||No|
|Redirect by cookie||No|
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