Caleb Macdonald Black
Caleb Macdonald Black

Reputation: 1572

Serve index.html without a redirect on 404 keeping url

I'm using an SPA and my local dev environment serves the index.html file for any 404s. This keeps the URL intact when loading the app. My apps routing picks up the URL and displays the correct page.

I currently have 404 redirects in s3 to index.html

Current behavior

Desired behavior

I'm hoping I can achieve this without needing to run a server

Upvotes: 1

Views: 1024

Answers (1)

Matt Houser
Matt Houser

Reputation: 36073

If you configure index.html for both Index Document and Error document with no redirects configured, then:

  • Request for www.example.com shows www.example.com/index.html with 200 status code, client sees www.example.com.
  • Request for www.example.com/sub1 (found) shows www.example.com/sub1/index.html with 200 status code, client sees www.example.com/sub1 with no redirect.
  • Request for www.example.com/sub1 (not found) shows www.example.com/index.html with 404 status code, client sees www.example.com/sub1 with no redirect.

There is no way to change this behaviour. If you want it different, then you'll need to use your own server.

Upvotes: 2

Related Questions