Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created June 17, 2023 18:32
Show Gist options
  • Save webgtx/a391bbb8c7adc732ae4d9cf873b00984 to your computer and use it in GitHub Desktop.
Save webgtx/a391bbb8c7adc732ae4d9cf873b00984 to your computer and use it in GitHub Desktop.
routing issue for SPA in the cloud

Redirects for single page web apps (SPA)

Most SPA frameworks support HTML5 history.pushState() to change browser location without triggering a server request. This works for users who begin their journey from the root (or /index.html), but fails for users who navigate directly to any other page.

The following example uses regular expressions to set up a 200 rewrite for all files to index.html, except for the file extensions specified in the regular expression.

rules = </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp)$)([^.]+$)/>

Original address Destination Address Redirect Type
rules /index.html 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment