Skip to content

Instantly share code, notes, and snippets.

@johnsoncodehk
Last active January 29, 2026 09:36
Show Gist options
  • Select an option

  • Save johnsoncodehk/77dcdd983c0c7234cd83408601148ce3 to your computer and use it in GitHub Desktop.

Select an option

Save johnsoncodehk/77dcdd983c0c7234cd83408601148ce3 to your computer and use it in GitHub Desktop.
Remove URL trailing slash
window.history.replaceState("", "", window.location.href.replace(new RegExp("/(?!.*/)"), ""))
@abderrahmanehadji-wq
Copy link

Have you tested this approach with URLs that include query strings or hash fragments? Curious about any edge cases.

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