S3 Static Site Hosting results in 403 redirect - Search Engines refuse to index

Hi,
I’m hosting a React PWA in an S3 bucket as a static site hosted with cloudflare configured over the bucket with a CNAME

image

So for example if you try and access:
https://www.k2nlearner.com/explore

You’ll get redirected to the index page.

However the error that AWS S3 gives is 403 then redirects the client to the index.html page

e.g. from a curl https://www.k2nlearner.com/explore -v

< HTTP/2 403
< x-amz-error-code: AccessDenied
< x-amz-error-message: Access Denied

So whilst the user gets redriected to the index and then React Router handles routing to the correct page, Google’s search engine crawler will refuse to index the page as it is a 403.

Is there a way in the Cloudflare settings to rewrite the 403 to a 301?

Or is this something that must be done in S3? ( I had a quick look and I don’t think it’s possible)

You could deploy a Worker script which intercepts requests to /explore and then does not simply tunnel through the 403 but instead returns a proper redirect, however in general this really is something you better fix on your server side.