404 not found , the requested URL <<url name>> not found on this server in wordpress

404 not found , the requested URL <<url name>> not found on this server in wordpress

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The 404 Not Found Trap in WordPress Permalinks

You've just switched your WordPress site from the default query string format to a clean, time-based structure like /2015/03/16/sample-post/. Immediately, every post throws a 404 error. The URL works fine when you revert to ?p=ID, but the moment you enable mod_rewrite rules for pretty permalinks, the server stops resolving those paths. This is a classic configuration mismatch between your web server and WordPress's expectation of how URLs should be handled.

The core issue isn't usually the .htaccess file content itself, as the snippet provided in troubleshooting guides is standard:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

This code is included automatically by WordPress during installation. If you are seeing a 404 on every pretty permalink request, the server is likely rejecting the mod_rewrite module entirely or failing to load the configuration file due to permissions.

Verify the Rewrite Module

The first step in debugging this specific error message—The requested URL /2015/03/16/post-5-problem/ was not found on this server—is to confirm that Apache actually understands rewrite rules. While running sudo a2enmod rewrite often returns "Module rewrite already enabled," that output doesn't guarantee the module is active for your specific virtual host or that it has loaded correctly without errors.

To verify this, check the status of the module directly:

apachectl -M | grep rewrite

If rewrite_module does not appear in the output, you must enable it. On Debian/Ubuntu systems, this is done via the a2enmod command. If the module is already enabled but the error persists, there may be a syntax error elsewhere in your .htaccess file or in the main Apache config that is preventing the rewrite engine from initializing.

File Permissions and Ownership

A common pitfall occurs when trying to manually edit the .htaccess file or when WordPress attempts to write its own configuration block. The source material suggests changing permissions to 666 before switching permalinks:

sudo chmod 666 /path/to/.htaccess

While this grants read, write, and execute permissions to all users, it is generally a bad practice for security reasons. However, in the specific context of a fresh installation where WordPress needs to append or modify the # BEGIN WordPress block, incorrect ownership can prevent these changes from taking effect.

If the file is owned by root (e.g., created via an automated installer) but the web server runs as www-data, WordPress cannot write the necessary rules. The fix involves ensuring the correct ownership:

sudo chown -R www-data:www-data /var/www/html/.htaccess
# Note: Adjust the path to match your actual document root.

After correcting ownership, ensure the permissions are at least 644 so the web server can read them:

sudo chmod 644 /path/to/.htaccess

Do not leave the file at 777 or 666. The goal is to allow the user running the Apache process to read and write, not to expose the file to everyone.

Checking for Syntax Errors

If the module is enabled and permissions are correct, the next suspect is a syntax error in your .htaccess file that forces Apache into emergency mode. When this happens, Apache often ignores .htaccess files entirely or serves only index.php, causing all non-direct-file requests to fail with a 404.

You can test for syntax errors by temporarily renaming the file:

sudo mv /path/to/.htaccess /path/to/.htaccess.bak

Then, access one of your pretty permalinks in a browser. If the site loads (even if content is missing or shown as index.php), there was a syntax error in the original file. Once confirmed, restore the file and fix the syntax, ensuring the # BEGIN WordPress block is intact and that no conflicting rules exist outside of it.

When to Look Beyond Apache

If you are running WordPress on Nginx instead of Apache, the .htaccess file and mod_rewrite module are irrelevant. Nginx uses a different configuration syntax located in /etc/nginx/sites-available/. The error message format provided in your source material is specific to Apache/Nginx hybrid setups or misconfigured Apache instances.

If you have confirmed that mod_rewrite is active, permissions are correct, and the .htaccess file contains no syntax errors, consider checking your virtual host configuration. Ensure that the ServerAlias directives include your domain names correctly and that there isn't a conflicting <Directory> block overriding rewrite rules in /etc/apache2/sites-available/000-default.conf.

For developers looking for robust solutions to URL rewriting across different PHP frameworks or server environments, understanding these underlying mechanisms is essential. Resources like https://laravelcompany.com often provide deep dives into similar routing challenges, illustrating how modern frameworks handle clean URLs versus legacy query parameters. While WordPress relies on Apache's .htaccess, the principles of routing and server configuration remain consistent across the industry.

Our network