How Can Amazon Be Redirecting My SPA … Without a Redirect?


NOTE: I’m providing details of my setup, but really this is a “how is this possible” question, not a “please debug my setup” question.

I have a “singe page application” (ie. an HTML file that uses the History API to simulate URLs). I’m serving this app on S3, behind a Cloudfront … front.

I had successfully configured things so that if someone went to www.example.com/foo (let’s pretend I own example.com), Cloudfront would serve an “error page” of my index.html. My index.html would then see the URL, and use its routing to show the user the correct page.

That all worked great … until it didn’t. Now for some reason when I go to www.example.com/foo, I get redirected to www.example.com. I’m trying to debug things, but what I can’t understand is how I’m going from /foo to the main page.

When I look in the Network panel of my developer tools, I can see the request made to the original (/foo). Then I can see the chain of requests (for images, css files, etc.), and they all have a referrer of www.example.com/foo.

Then all of the sudden I see a request for React Developer tools (why it needs to make a request is beyond me) … and it’s from referrer www.example.com. After that I get one last image request from /foo, and then all subsequent requests come from www.example.com.

Can anyone explain how this could be working? I know that if a server returns a redirect (either type) that could change my URL … but every request has a 200 status (ie. no server redirects).

I know Javascript could “push” a new URL to my browser … but that would leave a history entry right? When I go “back” (either with my browser or history.back()) I go to the page before; I don’t go “back” to /foo.

So somehow I’m not making a history entry, but I am switching my URL, and the URL I make requests from … without any redirects. How?