Post Date: January 17, 2021
Last Updated: November 23, 2026
Introduction
Are you experiencing a 404 Not Found error when accessing subpages of your website, even though your homepage loads correctly? This issue commonly occurs when Apache URL rewriting is not configured properly or when the required rewrite rules are not being processed.
A website’s homepage may work perfectly while internal pages return a 404 error. This can affect website navigation, user experience, and search engine crawling.
If your website is hosted on an Apache web server, enabling the Apache mod_rewrite module and configuring the appropriate directory permissions can help resolve this issue.
In this guide, we will explain how to fix the 404 Not Found error on website subpages using simple, step-by-step Apache configuration commands.
Why Does the 404 Not Found Error Occur on Website Subpages?
A 404 Not Found error occurs when the web server cannot locate or serve the requested URL.
Some common reasons include:
- The Apache mod_rewrite module is disabled.
- The AllowOverride directive is not configured correctly.
- Required rewrite rules are missing from the .htaccess file.
- Apache virtual host configuration is incorrect.
- The requested page or URL does not exist.
- The website’s DocumentRoot is configured incorrectly.
If your homepage works but internal URLs return a 404 error, checking Apache rewrite configuration is a good starting point.
How to Fix 404 Not Found Error on Website Subpages
Follow the steps below to enable Apache URL rewriting and configure your website’s Apache virtual host.
Step 1: Enable the Apache mod_rewrite Module
First, check whether the Apache rewrite module is enabled on your Ubuntu server.
Execute the following command:
sudo a2enmod rewrite
This command enables the Apache mod_rewrite module, which allows Apache to rewrite requested URLs based on configured rules.
Step 2: Restart the Apache Web Server
After enabling the rewrite module, restart Apache to apply the changes.
Execute:
sudo systemctl restart apache2
You can verify the module status using:
sudo apache2ctl -M | grep rewrite
If the module is enabled, you should see:
rewrite_module (shared)
Step 3: Configure the Apache Virtual Host
Next, configure the Apache virtual host file associated with your website.
Navigate to the Apache sites-available directory:
cd /etc/apache2/sites-available/
Open your website’s Apache configuration file:
sudo nano your-domain.conf
Locate the DocumentRoot directory of your website.
Add or update the following Directory configuration. Replace /var/www/html with your actual website document root.
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Configuration explanation:
- Options FollowSymLinks: Allows Apache to follow symbolic links.
- AllowOverride All: Allows permitted directives in .htaccess files, including rewrite rules.
- Require all granted: Allows access to the configured directory.
The AllowOverride directive is particularly important when your website uses .htaccess files for URL rewriting.
Save the configuration file and exit the editor.
Experiencing a 404 Not Found error when accessing your website’s subpages? Our team can help you troubleshoot Apache configuration issues, enable URL rewriting, resolve website errors, and provide reliable server administration and maintenance services.
Explore our DevOps & Cloud Services to learn more.
Step 4: Check the Apache Configuration and Restart
Before restarting Apache, verify that the configuration does not contain syntax errors.
Execute:
sudo apache2ctl configtest
If the configuration is correct, you should receive:
Syntax OK
Now restart Apache:
sudo systemctl restart apache2
Step 5: Verify Website Subpages
After restarting Apache, open your website in a browser and access its internal pages.
For example:
https://example.com/https://example.com/about-ushttps://example.com/contact

Check whether the subpages load correctly without displaying the 404 Not Found error.
If the issue persists, verify that the required .htaccess file exists in your website’s document root and contains the correct rewrite rules for your application.
Also check the Apache error log:
sudo tail -f /var/log/apache2/error.log
If you still experience the issue, check the requested URL, file paths, application routing configuration, and Apache virtual host settings.
Conclusion
The 404 Not Found error on website subpages can often occur due to incorrect Apache URL rewriting configuration. Enabling the Apache mod_rewrite module, configuring the AllowOverride directive, and restarting the Apache web server can help resolve this issue when rewrite configuration is the cause.
By following the steps explained in this guide, you can troubleshoot common Apache rewrite configuration problems and restore access to your website’s internal pages.
If the issue continues after applying these changes, investigate your website’s .htaccess rules, application routing, and Apache error logs to identify the underlying cause.
Frequently Asked Questions (FAQs)
1. Why does my website homepage work but internal pages show a 404 Not Found error?
This issue can occur when Apache URL rewriting is disabled or incorrectly configured. Missing .htaccess rewrite rules or incorrect application routing can also cause internal pages to return a 404 error.
2. How do I enable the Apache mod_rewrite module in Ubuntu?
You can enable the Apache rewrite module using the following command:
sudo a2enmod rewrite
After enabling it, restart Apache using:
sudo systemctl restart apache2
3. What is the purpose of AllowOverride All in Apache?
The AllowOverride All directive allows permitted configuration directives in .htaccess files to override settings defined in the main Apache configuration. It is commonly used when websites require .htaccess-based URL rewriting.
Related Articles
SSL/TLS Configuration and Verification on Linux
How to setup SSL Certificate in Nginx on Ubuntu 20.04
Talk to DevOps and Cloud Experts
Maintaining a reliable website requires proper server configuration, Apache optimization, URL rewriting, and regular infrastructure maintenance. At Pheonix Solutions, our team helps businesses manage their web servers, cloud infrastructure, application environments, and website performance.
We can help you with:
- DevOps and cloud services for cloud infrastructure management, automation, server configuration, and optimization.
- Website development to build secure, responsive, and high-performing websites.
- Software maintenance and support to troubleshoot website errors, maintain applications, and ensure smooth website operations.
Need help fixing Apache 404 Not Found errors, configuring mod_rewrite, resolving website subpage issues, or maintaining your server infrastructure? Talk to our DevOps and Cloud experts to discuss your requirements.
