Redirect non-existing routes to index.html for Generated Static Sites

Currently if a glitch project is a Generated Static Site it can not use a standard browser history based routeing scheme, it must use a hash based url scheme (e.g. If you want to just a standard scheme (like you’re out of luck. Once your project has gone to sleep and glitch serves the statically compiled site, if you try to load a route that doesn’t map to an actual file then it will just throw a 404. Which is frustrating since most modern static sites don’t work this way. Most statically generated sites with multiple routes have the web server setup such that any non-existing routes get redirected to index.html. Then it’s up to your app to decide if it’s a valid url that it should render a page for or return a 404.

I’m suggesting that for new projects glitch should start redirect non-valid urls to index.html for generated static sites and leave it up to the app to decide if it’s a route or not (or at least provide the option to make a glitch project behave this way).

To demonstrate this behavior I’ve remixed the react generated static site and simply removed the hash router leaving the standard routing behavior. This causes the about page to become immediately inaccessible as soon as the project switches to static mode: (accessible if the project code has been accessed in the last 5 minutes, otherwise not)

The project code:


This is a fantastic suggestion - in fact in the early days of generated static sites this was the behaviour by default. IMO that was a lot better, plus the react starter used proper routing back then iirc.
You absolutely have my vote (if I can free one up :pensive:)

Edit: I think originally they did something slightly different, for instance the 11ty starter gave a 404 error similar to the default on the old express project, and the react one was empty but with css or smth - but it was very similar to this.


Thanks for writing this up, I’m going to see if it’s possible for us to make it happen soon!


Great! Thanks for that :blush:

1 Like

I hate to be that “+1!” person, but this would make generated_static immensely useful for me. I normally do full pre-rendering that avoids the need for a 200.html solution (serve the contents of a given HTML file as a 200 response instead of producing 404’s). However, for dynamic routes this doesn’t work. I’m using querystring parameters for dynamic data in the interim, but I’d love to be able to have true support for pushState / History API in Glitch generated_static projects.

This feature is provided by most static hosting platforms:

Netlify: (docs) can be configured via _redirects file to serve an HTML file instead of 404’ing:

/*    /index.html   200 (docs) will serve a 200.html found in nearest parent directory instead of 404’ing

GitHub Pages: supports 404.html but not 200.html. Some folks are using <meta refresh> to hack around this.

Nuxt and a few other frameworks also generate 200.html by default.

It might also be a nice way to avoid folks creating projects that circumvent the static app serving restrictions (search this forum for “how would i switch not found page on static site”) or fronting a Glitch site with Cloudflare.


+1 from me too.