Fix Post Name 404 Issue in WordPress

For SEO purposes, post name URLs are often changed from Plain to Post Name. This is configured in the Permalinks page in the admin under Settings -> Permalinks.

Fix Post Name 404 Issue in WordPress

If your server’s configured correctly to run your WordPress website correctly, you shouldn’t experience any problems viewing posts using the post name permalink. However, there may be occasions where you find that you encounter a 404 Page Not Found issues when viewing the URL.

Fix Post Name 404 Issue in WordPress

There are a few things to check if your post name URLs are not working correctly.

Firstly, your WordPress installation should contain an .htaccess file in the root directory. The file may not be present when first installing WordPress, so you will need to create one.

The contents within .htaccess should contain the configuration recommended on the WordPress website.

# 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]
# END WordPress

The syntax above is responsible for rewriting the WordPress URLs correctly so that the post can display with the post name URL.

Secondly, you’ll need to check if the mod_rewrite Apache module is enabled on the server. The configuration within the <IfModule mod_rewrite.c> nodes will only run if the module has been enabled.

You can check if the module has been enabled using a couple of different methods. The first method is to log into your server via SSH and run the following command.

$ php -i

This will print out contents of the Apache modules and extensions loaded. You can also create a PHP file on the server that contains the phpinfo() function, view the file within the browser and search for any instances of ‘mod_rewrite’. If you do find instances, then it is likely that mod_rewrite is enabled.

If you do not have relevant access to execute commands or view this information, you will need to contact your hosting provider.

Another method of confirming if mod_rewrite is enabled is to deliberately add some code within the .htaccess file within the pair of <IfModule mod_rewrite.c> nodes that will cause apache to error, and probably cause a 500 internal server error on the WordPress website. The code will only run if the mod_rewrite module is enabled.

It should be noted that the above method should be tested temporarily, especially if you’re testing code changes on a live website!

The .htaccess file should also have correct permissions and that the file is owned by the web server process itself. Sometimes this is the www, apache or the nobody user.

Usually the file ownership will be the same as the other WordPress files on the server. Be sure to check the above steps and confirm with your hosting provider that mod_rewrite has been enabled correctly, and your post name URLs should work without a problem.

Note: This article is based on WordPress version 4.9.