HTTP Error Codes Explained & How to Fix Them
In this article
The most common HTTP error codes are the 4xx (client-side) and 5xx (server-side) statuses you see when a web page fails to load. In short: 404 means the page is missing, 403 means access is denied, 500 means the server crashed, and 502/503/504 are gateway or overload problems. This guide explains each code in plain language and walks you through the exact troubleshooting steps to resolve them, whether you're a website owner or just trying to access a site.
What You'll Need
- A web browser (Chrome, Firefox, Safari, Edge)
- Access to the website's server logs or hosting control panel (if you own the site)
- An FTP client or file manager (for editing server files, if needed)
- Command line access (for curl or ping tests) – optional but helpful
- Basic knowledge of your hosting provider's dashboard
Step-by-Step
1. Identify the exact error code
- Look at the browser tab or the error page itself – the code is usually displayed as a number (e.g., 404, 500).
- If the page shows a generic message, open the browser's developer tools (F12 on Windows, Cmd+Option+I on Mac) and go to the Network tab. Reload the page and click on the failed request to see the exact status code.
- Write down the code – different codes have different fixes.
2. Troubleshoot 404 Not Found
- Check the URL for typos – a single wrong letter or a missing slash can cause a 404.
- If you're the site owner, verify that the file or page actually exists in your hosting file manager or via FTP.
- If the page was moved or renamed, set up a 301 redirect from the old URL to the new one (in .htaccess on Apache, or via your CMS's redirect plugin).
- If the page is missing entirely, restore it from a backup or recreate it.
3. Troubleshoot 403 Forbidden
- Check file permissions – on Linux hosting, directories should be 755 and files 644. Use your FTP client to right-click and set permissions.
- Look for an .htaccess file that may be blocking access – rename it to .htaccess.bak and test.
- If you're using a security plugin or firewall (like Wordfence or Cloudflare), temporarily disable it to see if it's blocking you.
- If the site is password-protected, ensure you're entering the correct credentials.
4. Troubleshoot 500 Internal Server Error
- Check the server error log – in cPanel, look under “Error Logs” or “Raw Access Logs”. The log will show the exact file and line causing the issue.
- If you recently edited a .htaccess file, revert it to the default version (usually just:
RewriteEngine On). - If you use WordPress, temporarily rename the plugins folder (via FTP) to
plugins_oldand see if the site loads – if it does, one plugin is the culprit. Then rename individual plugin folders to find the bad one. - If the error started after a PHP update, check for deprecated functions in your theme or plugins – update them or switch to a default theme.
5. Troubleshoot 502 Bad Gateway
- Restart your web server and PHP process – in cPanel, use the “Restart PHP” option, or ask your host to do it.
- If you're using a reverse proxy (like Nginx in front of Apache), restart both services.
- Check if your CDN or load balancer is down – visit their status page.
- If you're on shared hosting, contact your provider – the issue may be on their end.
6. Troubleshoot 503 Service Unavailable
- Wait a few minutes – the server may be temporarily overloaded or under maintenance.
- If you're the site owner, check if you've exceeded your resource limits (CPU, memory) in your hosting dashboard.
- Look for a maintenance mode flag – in WordPress, delete the
.maintenancefile from the root directory if it exists. - If the server is genuinely down, restart it from your hosting control panel or contact support.
7. Troubleshoot 504 Gateway Timeout
- Increase the PHP execution time limit – in .htaccess, add
php_value max_execution_time 300(or edit php.ini). - If you're using a proxy, increase the proxy timeout setting in Nginx or Apache configuration.
- Check for a slow database query – optimize your database tables or enable caching.
- If a specific script is timing out, debug it by enabling error reporting in PHP.
Common Mistakes
- Ignoring the error log – many people guess instead of reading the log, which usually points directly to the cause.
- Changing file permissions randomly – setting everything to 777 can create security holes; use 755 for directories and 644 for files.
- Deleting .htaccess without a backup – always download a copy before editing or removing it.
- Assuming the problem is on your side – for 502/503/504, check the server status page or your hosting provider's announcements first.
- Not clearing your browser cache – a cached error page can persist even after you fix the issue; hard refresh (Ctrl+F5) to test.
Tips
- Use
curl -Ifrom the command line to see the exact HTTP status code without loading the full page. - For WordPress sites, enable debugging by adding
define('WP_DEBUG', true);to wp-config.php to see the actual error message. - Set up a monitoring service (like UptimeRobot) to alert you when your site returns a 5xx error.
- Keep backups – before making any server-side changes, back up the file you're editing.
- If you're not comfortable with server configuration, most hosting providers offer free support – use it.
Troubleshooting
If the steps above didn't resolve the issue:
- Restart everything – restart your browser, your router, and if possible, the web server. Sometimes a temporary glitch clears itself.
- Check if the problem is on your network – try loading the site from a different device or a mobile hotspot. If it works there, the issue is local.
- Use a different DNS – sometimes DNS caching causes errors; flush your DNS (ipconfig /flushdns on Windows) or switch to Google DNS (8.8.8.8).
- Contact your hosting provider – for 5xx errors, they can see server logs and often fix the issue faster than you can. Provide them with the exact error code and the time it occurred.
- If the error is on a site you don't own – there's nothing you can do except wait and try again later. You can use a service like “Down For Everyone Or Just Me” to confirm it's not just you.
Frequently Asked Questions
What's the difference between 401 and 403?
401 Unauthorized means you haven't provided valid credentials (you're not logged in). 403 Forbidden means you're logged in but don't have permission to access that resource.
Why do I see a 404 on a page that exists?
This often happens due to a broken permalink structure (in WordPress, go to Settings > Permalinks and click “Save Changes” to reset), or a missing .htaccess rewrite rule.
Can a 500 error be caused by a plugin?
Yes, especially in WordPress. A poorly coded plugin can conflict with your theme or PHP version. Disable all plugins and re-enable them one by one to isolate the culprit.
How long does a 503 error usually last?
It depends. If it's due to maintenance, it may be minutes. If it's due to resource limits, it could last until you upgrade or optimize. If it's a server crash, it may take hours – contact your provider.
Is a 502 error my fault?
Usually not. A 502 means the server acting as a gateway received an invalid response from the upstream server – this is typically a server-side issue, not a problem with your browser or network.
Should I use a plugin to fix HTTP errors?
For WordPress, there are plugins that can help with .htaccess or cache issues, but the root cause is often server configuration. It's better to fix the underlying issue manually or with host support.