Created
March 30, 2023 19:25
-
-
Save srhyne/855a4dea1394ebac03def06c8a1ba3bb to your computer and use it in GitHub Desktop.
Fix Cloudflare 308 trailing comma redrect issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix Cloudflare 308 trailing comma redrect issue | |
# https://community.cloudflare.com/t/cloudflare-pages-get-rid-of-redundat-308-redirect/324582/29 | |
# https://electricui.com/blog/switching-to-cloudflare-pages#how-to-disable-the-trailing-slash-on-cloudflare-pages | |
find ./dist -name 'index.html' -mindepth 2 -type f \ | |
-exec sh \ | |
-c 'parent="$(dirname "$1")"; mv "$1" "$parent/../$(basename "$parent").html";' \ | |
find-sh {} \; | |
find ./dist -empty -type d -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix Cloudflare 308 trailing comma redrect issue
This script works by
converting => /blog/post-slug-name/index.html
to => /blog/post-slug-name.html
Logically, Cloudflare things that /blog/post-slug-name/index.html is going to be a folder including more content. So they add the trailing / comma to the end of the request and use a 308 redirect in the process! 😮💨
How I used
npm run build && bash ./src/scripts/migrate-index.sh
Of course you could add the migration into your
npm run build directly