Best practices
Beyond how Cloudflare uses redirects, we follow these best practices.
As much as you can, try to organize your redirects into logical groups (products, alphabetical order). This process helps prevent duplicate redirects, as well as identifying specific ones you might be looking for.
In our Pages _redirects
file ↗, we use extensive comments, separating different product areas. We also try, as much as we can, to keep the redirects in alphabetical order within a section.
We used to apply a similar principle to Bulk Redirect lists (when that was our primary method). We created lists that grouped together similar products and labeled them as such, so it was easier to find which redirect you were looking for.
At the server level, you can trigger a redirect on a URL path (/page/
), but not a fragment (/page/#fragment
).
You can redirect a page to a fragment, however (/page1/
to /page2/#fragment
).
Particularly in an open-source environment, use automation to identify changes that might require redirects. We built a GitHub action ↗ specifically for this use case.
You should apply a similar process to infinite redirects (where two redirect rules point to each other), if possible, and redirects containing a source URL fragment, which are invalid. We have a dedicated script ↗ to check for these situations in our Pages project.