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

Redirects

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:

_redirects
/home301 / 301
/home302 / 302
/querystrings /?query=string 301
/twitch https://twitch.tv
/trailing /trailing/ 301
/notrailing/ /nottrailing 301

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. If the same source URL has multiple redirects, the topmost redirect is applied.

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

FeatureSupportExample
Redirects (301, 302)Yes/home / 301
Rewrites (other status codes)No/blog/* /blog/404.html 404
SplatsNo/blog/* /blog/:splat
PlaceholdersNo/blog/:year/:month/:date/:slug /news/:year/:month/:date/:slug
Query ParametersNo/shop id=:id /blog/:id 301
Force (shadowing)No/workers/ /workers/index.html 200!
Domain-level redirectsNoworkers.example.com/* workers.example.com/blog/:splat 301
Redirect by country or languageNo/ /us 302 Country=us

Additional information