{
  "$type": "site.standard.document",
  "canonicalUrl": "https://www.simoncox.com/short-articles/2025-10-08-creating-cloudflare-redirects/",
  "description": "How to manage redirects on a Cloudflare Pages site using a _redirects file — notes from migrating directory structure in an 11ty build.",
  "path": "/short-articles/2025-10-08-creating-cloudflare-redirects/",
  "publishedAt": "2025-10-08T00:00:00.000Z",
  "site": "at://did:plc:tki7vwlanxbwrz2er67eaeqa/site.standard.publication/3mp4h4md7zv2y",
  "tags": [
    "Web",
    "Eleventy"
  ],
  "textContent": "I was having issues sorting out the redirects on Cloudflare and have learnt a few things on the way so am documenting them here – because I will forget it all whilst in the pursuit of happier things.\n\nDirectory migration\nI made a major change to the structure of a section of my site /shorts/ has reverted back to /short-articles/ as I am testing out a possible issue with this sites current  lack of SERP visibility in Bing. As such I needed to revert the redirects from /short-articles/ to /shorts/ back again. Not usually an issue for my skills but I thought I'd make some notes.\n\nCloudflare hosting\nThis site is currently hosted on Cloudflare pages, auto deployed from its github repository. I can use the inbuilt redirect solution that Cloudflare provides but that has a very limited capacity so I have created a file named _redirects that Cloudflare recognises (as does Netlify) and uses for redirects. This is in my 11ty setup and has a passthrough so that it is output in the build exactly the same as I have written it. \n\nThis file can have up to 2,000 redirects if properly formatted. I have had issues with only being able to use 120 redirects but this was because I had built some of them incorrectly. \n\nDeployment logs \nOne source of info that is really useful is the deployment log files. Find it here:\nCloudflare > Compute (Workers) > your site > View details\n\nNow scroll down in the Build log and it will tell you all sorts of interesting things such as time and what happened. This includes parsing the redirects file.\n\nThe log helpfully tells you redirects that have not been implemented and also provides some optimisation suggestions such as the order of the redirects. \n\nNotes on Cloudflare redirect rules best practices\n\nExclamation mark on the end of the rule\nI think this was a leftover from Netlify's redirect rules\n\nI did a find and replace and removed the exclamations marks.\n\nThere was another issue with this particular rule though! \n\nOnly relative URLs are allowed\nI had some domain redirects in place, because you can't have enough domain names, but Cloudflare doesn't like them as the source URL, they have to be a part of the directory structure, so I had to take them out. \n\nI am now forwarding those domains using an external method.\n\nRedirect rule spaces and or tabs\nCloudflare is quite particular about the number of spaces - it looks for gaps in the redirect rule of 2 and 3 sets of spaces or tabs. If there are 4 or more sets of spaces and the rule will be ignored.\n\nThis means if your URL has a space you will need to use %20 in place of the space:\n\nColons interpreted as placeholders\nI have some URLs with colons in them, such as /blog/category:things, and have put these under section 2 as the colon is interpreted as a placeholder, or you can URL-encode the colon of course!\n\nOrder of redirect rules\nFor performant reasons it is better to list static redirects before dynamic ones so that Cloudflare’s systems can run these more effectively:\n1. Static rules - /home, /about, /contact\n2. Rules with placeholders - /blog/:slug, /users/:id\n3. Rules with splats - /old-site/\n\nI split these up using comments in my redirect files.\n\nFinal thoughts about the Cloudflare redirect file rules\nI originally thought I could switch the sites hosting between Cloudflare and Netlify hosting by just changing the DNS, a very handy and quick solution, but I am not going to have to keep two sets of redirect files if I want to do this as the rules are quite different between them. \n\nHaving learnt more about the Cloudflare redirect rules If am much happier running the rules from this file. Also, this started off as a shorticle but is long enough to be a full article. \n \nYou can read more on Cloudflare’s full documentation on redirects and let me know if I have missed anything important out!",
  "title": "Creating Cloudflare redirects"
}