Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force 200 response codes from Azure Static Website - SPA (Google won't index routes)

I have a React SPA that is being hosted as an Azure Static Website. The configuration is rather simple - html, js etc files are deployed to Azure Storage. I then enable the static website feature and expose this via a Verizon Premium CDN Endpoint.

The Static Website is configured to serve index.html as the index and error document. The issue that I am seeing here is that when a route is requested /faqs for example the response is a 404 with the index.html doc as the response body - this works fine in the browser but Google will not crawl it as it's seeing the response as a 404.

I wonder if there is anyway around this? Is there anyway to force 2** response codes?

like image 444
jonytek Avatar asked Sep 19 '25 21:09

jonytek


2 Answers

Well after messing around trying to configure Azure to force status codes I found a solution, it's not ideal but it works and will be fine for now.

SOLUTION: I cloned my index.html as faqs (no extension so manually set content type) so that the respective version is served when requested. Happy days! Glad I only have a small number of public pages.

like image 152
jonytek Avatar answered Sep 21 '25 22:09

jonytek


Since you have the CDN layer in front of your website, you can have the CDN deliver the index.html via a URL rewrite rather than relying on the static website's "error page" delivery mechanism. This holds up even if you have a variable number of routes in your application.

Configure a rule in your CDN's Rules Engine that takes any path without a file extension (since we want normal requests for assets or script/style files to return those actual files) and rewrites to /index.html. Re-write means the URL of the actual request remains the same, but the file that gets delivered comes from the rewritten URL.

See this article for more.

like image 27
tplusk Avatar answered Sep 21 '25 22:09

tplusk