Skip to content

Instantly share code, notes, and snippets.

@salomvary
Created December 4, 2023 19:51
Show Gist options
  • Save salomvary/b123f403521d68a4d852b848d541d88f to your computer and use it in GitHub Desktop.
Save salomvary/b123f403521d68a4d852b848d541d88f to your computer and use it in GitHub Desktop.
Get rid of Netlify "Pretty URLs" when using Jekyll

Disable Netlify's Pretty URLs feature and add redirects to avoid breaking links to your site.

Followup to my rant on Twitter.

  1. Turn off Pretty URLs on Netlify under Siteconfiguration > Build & deploy > Post processing > Pretty URLs
  2. Build the site locally, by running jekyll build.
  3. Run for url in $(find _site -name "*.html" -not -name "index.html"); do echo "$(echo $url | sed s,_site,, | sed s/.html//) $(echo $url | sed s,_site,,)"; done >> _redirects
  4. Run for url in $(find _site -name index.html -not -path _site/index.html); do echo "$(echo $url | sed s,_site,, | sed s,/index.html,,) $(echo $url | sed s,_site,,)"; done >> _redirects
  5. Commit and push _redirects.

Assumes a default Jekyll configuration, tweak the shell commands when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment