Case Study: 404 Errors When You Change Your Permalinks

I have had a number of clients come to me with this problem, so I thought a case study was in order.

Here’s the Problem

When you change the permalinks from the default to something more pretty and SEO friendly, you click on a post or page link and all you get is a 404 file not found error. This is done from the settings-> permalink page.

The home page will be fine, but you cannot access any of your content off of the home page.

What Is A Permalink

A permalink is the URL of your blog post or page, the bit after your domain name for example the permalink of this post is case-study-errors-when-change-your-permalinks.

By default the permalink for a post or page is set to the post ID, so if I was using default permalinks, this post would look like this ibraininc.com/?p=5770

What Having Pretty Permalinks Matters

It is a good idea to change your permalinks from the default to a pretty permalink (pretty is the technical term BTW, don’t believe me check out http://codex.wordpress.org/Using_Permalinks) for SEO purposes.

You can stuff valid keywords into the permalinks of your post to help the search engines match your content with searchers.

So What Has Happened?

When you change from the default to pretty permalinks WordPress needs to setup a redirect to the new URL, it does this by adding some commands to the file .htacess.   This file lives in the root of your site.

What Might Cause the Problem?

There are a couple of reason why this might not work, the first is that mod_rewrite is not installed on your hosting,  Check with them to see if they have this redirection technology in place.  I have not seen many hosting setups where this is not in place so you can probably move onto the next point.

Another reason I have seen 404 problems is when the .htaccess cannot be written to.  This might be file permissions or the file does not exist and WordPress cannot create it.

The Fix

Connect to your site using ftp and open up the .htaccess file.  NOTE some ftp client do not show hidden files by default so you may need to enable this. anything starting with a period/full stop is marked as hidden.

Edit the .htaccess file and see if it contains the following set of commands:

# 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

If they are not present, you probably are having problems writing to the .htaccess file you can either change the permissions of .htaccess and try to regenerate the permalinks (you do this by setting it back to default, then setting it to pretty permalinks again) or you can manually edit and add the commands.

Please note if you are running WordPress in a subdirectory, you will need to reflect this in the command you add to the .htaccess file. Upload the file again and the 404 errors should be gone.

Wrap Up

So if you get 404 file not found errors when you change your permalinks, you need to manually edit your .htaccess file, if that doesn’t work check mod_rewrite with your hosting company, you can always roll back to the default permalink structure until you get this fixed to get your site back online

Image by everdred

Leave a Reply

Your email address will not be published. Required fields are marked *