Troubleshooting
404 error on static files with the correct path
If an image, a CSS file or a JavaScript file returns 404, check the URL the browser is actually requesting. The file existing on your computer or in another folder of your hosting doesn't mean it exists in that domain's public root.
Confirm what is responding
- Check the response's status code, headers and body. Tell a 404 from the application apart from one from the server or the CDN.
- Review the access and error logs for the same URL and time.
- Confirm that the file exists in the domain's
DocumentRootand that upper case, lower case and extension match exactly.
Permissions problem
Check against Hostsuar's policy: 755 for directories and 644 for files. A permissions problem usually returns 403 or leaves a denial in the log; don't treat it as the cause of the 404 without that evidence.
Framework intercepting requests
A common setup lets the server deliver existing files and sends only paths that don't exist to the front controller. In the applicable .htaccess, check whether the !-f and !-d conditions are there or whether an earlier rule intercepts the URL.
Don't add RewriteEngine Off across the board: it can turn off legitimate access, security, caching or alternative format rules. Fix or narrow only the rule that the logs and a controlled test identify.
ModSecurity block
If the real error is a 403, look up the ModSecurity audit event for that URL and time before concluding it is a false positive. Identify the exact rule and, if appropriate, request an exclusion limited to that rule and the specific path.
Don't turn off ModSecurity across the board as a fix. Only to confirm the diagnosis, a test lasting a few minutes with a single request can be run, turning it back on immediately afterwards whatever the result.
After a deployment
If the file name includes a version or hash, check that the HTML doesn't point to a file from an earlier build that has already been deleted. Publish the new resources before the HTML that references them, and keep the old ones while open or cached pages may still use them.
In the Network tab, open the failed request and review its full URL and its initiator. A relative path inside a CSS file is resolved relative to that CSS file, not to the HTML page. Fix the reference at its source and then purge only the affected caches; some CDNs also cache 404 responses.
You may also find useful
- 503 Service Unavailable error Diagnose a 503 from the response, logs and metrics at the same moment to tell the application, maint...
- Diagnose the 503 Overloaded error in PrestaShop Tell a PrestaShop 1.6 geographic block apart from maintenance mode and a server-generated 503 before...
- Internal server error when accessing email through Webmail Tell an internal Webmail error apart from a quota warning and check the mailbox, total disk space or...
- "An error occurred while sending the message" in the PrestaShop contact form Diagnose the contact form rejection and fix an old override only when it does not send contactform's...
Something wrong or out of date? Tell us and we will review it.