Search code examples
.htaccessmanifest.json

Why Server Responds manifest.json Request With index.html?


.htaccess

# force traffic to https
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# serve index.html for any unknown paths
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

because the request returned is index.html browser throws error like this Manifest: Line: 1, column: 1, Syntax error.

All Requests For Script Or Css Work Except This One.


Solution

  • My guess would be that you are using a relative URL-path in your client-side JavaScript to this manifest.json file so the browser resolves this incorrectly (relative to the URL in the address bar, not the file-path on the server as you are perhaps expecting), resulting in a 404 (which routes the request to index.html).

    You need to use a root-relative (starting with a slash) or absolute (scheme + hostname) URLs when referencing any assets from client-side code when you are rewriting the URL from different URL-path depths.