Troubleshooting
404 error on images, CSS or JS with the correct path
Sometimes you link an image, a CSS file or a JavaScript file, you are sure the path is correct, and the server still replies that it cannot find it (404 error). These are the most common causes, from the simplest to the least simple.
The URL is not exactly what you think
Open the website, press F12, go to the Network tab and reload. Click the file that fails to see the full URL the browser requests. Compare it with the file's real location in the File Manager:
- Upper and lower case: on the server
Logo.pngandlogo.pngare different files, even if it works on your computer. - Domain folder: the file must be inside that domain's folder (
public_htmlor the addon domain's folder), not in another one. - Paths inside a CSS file: a relative path such as
url(img/fondo.jpg)inside a CSS file is looked up from the CSS file's folder, not the page's. - Files with a version or hash (
app.3f9a1c.js): after updating the website, the page may still be requesting the old file you have already deleted. Clear the application's cache and, if you use a CDN, the CDN's cache.
Permissions problem
Check that the folders, subfolders and the files themselves have permissions of 755 for folders and 644 for files. You can change them from the cPanel File Manager with right-click > Change Permissions. Never use 777: it is not needed, as we explain in why you do not need 777 permissions.
The framework intercepts the requests
Frameworks and applications such as Laravel, Symfony or CodeIgniter send every request to their index.php through .htaccess rules, and those rules also affect every subfolder. If the rules do not exclude files that exist, the framework replies 404 to your images or CSS.
Open the .htaccess in the website's root and check that these two conditions come before the rule that sends everything to index.php:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L]
With them, if the file or folder exists, the server serves it directly. Current versions of the frameworks already include them; the problem usually occurs in old versions or in .htaccess files edited by hand.
If you cannot touch that .htaccess, create another one inside the folder containing the static files that fail, with this line at the beginning:
RewriteEngine Off
That disables the rewrite rules only in that folder, and the rest of the website keeps working as before.
ModSecurity block (403 error)
If in the Network tab the error is not 404 but 403, the ModSecurity firewall is most likely blocking the file by mistake, for example because of its name or the URL parameters. Disable it briefly for the domain, reload the page and enable it again straight away.
If the file loads with ModSecurity disabled, write to us with the exact URL and the time: we will create an exception just for that rule and that path, so you do not have to leave it disabled.
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.