If you’ve ever visited a website and seen a message like:
404 Error – Page Not Found
you’ve encountered one of the most common — yet easily fixable — issues on the web.
A 404 Error simply means that your web server could not find the page (file) that the visitor or browser requested. In other words, the URL exists, but the requested file doesn’t — or isn’t accessible where it should be.
This error can appear on HTML websites, PHP-based websites, WordPress, or any framework like CodeIgniter or Laravel. It doesn’t necessarily mean your website is broken — it just means your server cannot locate the requested file.
Let’s explore what causes this issue and how to fix it permanently. If you want to explore what is 404 error? Or maybe you are looking to customize WordPress’s 404 error page.
🔍 What Causes “404 Page Not Found” Error in HTML and PHP Sites?
Here are the most common reasons why your website might show a 404 error:
1. The File or Page Does Not Exist
The most obvious reason — the requested HTML or PHP file simply isn’t there. Maybe it was deleted, renamed, or moved to a different folder without updating the links.
Example:
You visit:
https://example.com/about.html
but the file is actually named about-us.html. The server looks for about.html, doesn’t find it, and returns a 404 error.
2. Wrong File Path or Directory Structure
In PHP websites, if you include or require files incorrectly, your pages might not load correctly and trigger a 404.
Example:
include('pages/home.php');
If the pages directory or the home.php file is missing or incorrectly placed, your server will return a 404.
3. Incorrect URL or Typos
A small typo in the URL can easily cause this issue.
For example, /contact.htm instead of /contact.html or /index.php instead of /home.php.
4. .htaccess Misconfiguration (in PHP or Apache)
If your website uses Apache and relies on an .htaccess file for URL rewriting, an incorrect rewrite rule can break URLs.
This is common in frameworks like CodeIgniter, Laravel, or CMSs like WordPress.
5. Moved Website Files or Folder Structure Changes
If you migrated your website from one host to another, changed directory structure, or installed SSL (https://), paths may have changed, leading to 404s.
6. Broken Internal or External Links
Links that point to old or deleted pages cause 404 errors.
This is common after redesigns or restructuring of website URLs.
7. Server Configuration Issues
Sometimes the issue isn’t your files — it’s the server configuration.
If the server isn’t properly interpreting .php or .html files, or directory indexing is disabled, it can throw a 404 even for existing files.
🛠️ How to Fix “404 Page Not Found” in HTML Websites
If you’re running a static HTML site, fixing this issue is generally simple. Follow these steps:
1. Check File Names and Paths
Verify that the requested file actually exists in your server directory.
Example structure:
/public_html/
├── index.html
├── about.html
├── contact.html
If the visitor requests /contact.html, make sure contact.html exists in /public_html/.
Pro Tip: File names are case-sensitive on Linux servers, so
About.html≠about.html.
2. Update Broken Links
Check your internal links (menus, buttons, or footers) to make sure they point to valid pages.
Example:
<a href="about.html">About</a>
If the actual file is about-us.html, fix the link accordingly.
3. Check Domain and Subdirectory Paths
If your site is in a subdirectory like /site/, make sure URLs reflect that path:
https://example.com/site/about.html
not just /about.html.
4. Upload Missing Files
If you’ve recently migrated your website, ensure that all files were uploaded correctly. Sometimes FTP uploads can fail silently, leaving missing pages.
5. Add a Custom 404 Page
Even when errors occur, you can display a friendly 404 message to users instead of a blank error.
Create a file called 404.html and add:
<!DOCTYPE html>
<html>
<head>
<title>Page Not Found</title>
</head>
<body>
<h1>Oops! Page Not Found</h1>
<p>The page you are looking for might have been moved or deleted.</p>
<a href="/">Go back to Home</a>
</body>
</html>
Then, configure your web server or .htaccess to use it.
⚙️ How to Fix “404 Page Not Found” in PHP Websites
If your website is dynamic and uses PHP, there are additional things to check.
1. Check PHP File Existence
Make sure the requested PHP file actually exists in your root or subfolder.
Example:
/public_html/
├── index.php
├── contact.php
└── about.php
If you request /about.php, but it’s actually /pages/about.php, update your links accordingly.
2. Check .htaccess Rewrite Rules
A major cause of 404s in PHP sites is incorrect .htaccess rules.
Open your .htaccess file and look for something like:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This configuration ensures all URLs are redirected through index.php, which is required for frameworks like CodeIgniter or Laravel.
If your .htaccess file is missing, your server may not know where to route requests — causing 404s for dynamic URLs.
3. Enable URL Rewriting
Make sure mod_rewrite is enabled on your Apache server.
You can ask your host to enable it or use the following command in Ubuntu:
sudo a2enmod rewrite
sudo service apache2 restart
4. Check Case Sensitivity
Again, Linux servers treat file names as case-sensitive.
So About.php ≠ about.php.
5. Check Framework Routing (CodeIgniter, Laravel, etc.)
If you’re using a PHP framework:
- In CodeIgniter, check
routes.phpin/application/config/. - In Laravel, check
web.phpin/routes/.
A missing or incorrect route will trigger a 404.
6. Fix 404 Error for PHP Includes
Sometimes, an include path may be broken:
include('header.php');
If header.php is in another directory like /includes/header.php, update the include path accordingly.
🧱 Creating a Custom 404 Error Page in PHP
Instead of showing a boring browser message, create a friendly PHP 404 page:
<?php
http_response_code(404);
?>
<!DOCTYPE html>
<html>
<head>
<title>404 - Page Not Found</title>
</head>
<body>
<h1>Sorry, this page doesn’t exist!</h1>
<p>The page you are looking for might have been removed or renamed.</p>
<a href="/">Return to Home</a>
</body>
</html>
Then in .htaccess, add:
ErrorDocument 404 /404.php
This ensures every missing page will load your custom 404.php file.
🔧 How to Test for 404 Errors on Your Website
- Use Google Search Console:
Go to “Coverage” → “Errors” → “Not Found (404)” section. - Use Broken Link Checker Tools:
Tools like Ahrefs, Screaming Frog, or BrokenLinkCheck.com help find dead URLs. - Manually Test Important Pages:
Open major pages and ensure they work fine after migration or updates.
🧩 Preventing 404 Errors in the Future
To avoid these errors long-term:
- Use consistent naming conventions (all lowercase).
- Always update internal links when moving files.
- Set up redirects (301) for deleted or moved pages.
- Regularly scan your website for broken links.
- Use a reliable web host that supports proper rewrite rules and PHP configurations.
🚀 Don’t Know How to Fix 404 Errors? Move to a Better Web Host
If you constantly face 404 issues or broken URL errors, it might be due to poor server configuration or missing rewrite support.
Switch to WebfulHost — a reliable web hosting solution optimized for HTML, PHP, and CMS frameworks.
Enjoy fast servers, free migration, and expert technical support to keep your website running error-free.
❓ Frequently Asked Questions (FAQs)
1. What does a 404 error mean?
It means the server couldn’t find the requested web page or file. The URL exists, but the actual file or path doesn’t.
2. Can I fix a 404 error myself?
Yes. Most 404 errors are caused by incorrect file paths, missing files, or misconfigured .htaccess files — all of which you can fix manually.
3. How do I fix 404 errors in PHP?
Check your .htaccess file, ensure PHP files exist, confirm URL rewrite rules, and verify correct routes in your framework (like CodeIgniter or Laravel).
4. Do 404 errors affect SEO?
Yes. If too many pages on your site return 404 errors, search engines may reduce crawl frequency and lower your SEO ranking.
5. How can I set up a custom 404 page?
Create a 404.html or 404.php file and define it in .htaccess using:
ErrorDocument 404 /404.html
6. Why do my URLs work locally but not online?
Local servers (like XAMPP) are often case-insensitive, but live Linux servers are case-sensitive — so mismatched capitalization can cause 404s.
🏁 Conclusion: Keep Your Links Clean and Server Configurations Correct
A 404 Error Page Not Found can frustrate visitors and harm your SEO if not fixed promptly.
Thankfully, most of these issues boil down to missing files, typos, or .htaccess misconfigurations.
By keeping your directory structure organized, file names consistent, and redirects updated, you can ensure your HTML or PHP website runs smoothly — with zero broken links.
