How (and why) to change your WordPress permalink structure

Sorry for geeking out here, but I just discovered the solution to a longstanding problem and I haven’t seen a complete discussion anywhere else. So here goes…

The problem has to do with WordPress permalinks. A blog post’s permalink is the URL that search engines and directories use to find it on a WordPress blog like the one you’re reading. If a permalink changes for an existing post, the post disappears and searchers get a 404 error which not only is frustrating, but will cost you big time in the search rankings.

So why in the world would you want to change your permalinks in light of this risk? Because most of us made a mistake in the way we set up our permalinks to begin with. There’s a “Permalinks” tab in “Settings” on the WordPress dashboard and radio buttons to choose your structure and the default (as I recall) is to give each post a unique number like:

http://www.yoursite.com/blog/?p=123

But instead I thought it was useful to reference the date (at the beginning of Otisregrets, I was using it primarily as a communications tool in my copywriting class so it was important to have everything in chronological order) so I chose this option:

http://www.yoursite.com/2013/05/sample-post/

There are two things wrong with that structure. First, it means that every time a search result lists my post it will include the date. And I think most people give more credence to recent posts since an older one may have obsolete information. Second, you may want to republish older posts (like the ones from the early days of a blog, when you had far less readership). You can’t simply cut and paste to create a duplicate post; the search spiders hate this. But if you change the publication date in the WordPress dashboard to create a new post, then all your indexing disappears.

What I wanted to do is change the permalink structure to

http://www.yoursite.com/sample-post/

which means I can change the publication date (but NOT the title) and the search engines and indexes will still find it, yet it will be on the top page of my blog. And if you look at the urls of my posts now, that’s what I did. Here’s how.

1. Download your .htaccess file, which is in the top level directory of your WordPress blog. (Mine is in www.otismaxwell.com/blog for example.) This is the file which directs spiders and other indexing operations (including your own) as to where to find things on your site. You might not see the file immediately because many ftp applications hide “dot” files by default. I used Filezilla which has a setting under “Server” for “Force showing hidden files”; you want to check this setting and then .htaccess appears.

2. Make the .htaccess file visible on your local machine. This is necessary because neither Mac OS X nor Windows shows these files by default. In Mac it’s a simple matter of opening the Terminal and adding this line:

defaults write com.apple.Finder AppleShowAllFiles YES

After you do this, close terminal and restart Finder and voila, all your hidden files are now visible.

3. make a copy of the .htaccess file you downloaded and move it to a safe place on your local computer in case something terrible happens.

4. Open the .htaccess file in a text editor (I used TextEdit) and insert a line under # BEGIN WordPress to specify a 301 redirect. DO NOT MAKE A MISTAKE HERE OR YOUR POSTS WILL DISAPPEAR. Web programmer and SEO expert Joost de Valk has kindly provided a script which will create the correct code for you; read the article then click “generate redirects” and follow the prompts to create your own like of 301 code.

The revised code will look something like this:

# BEGIN WordPress
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ http://www.yoursite.com/$3
<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

5. Upload the edited .htaccess file to your WordPress directory, replacing the old file, then IMMEDIATELY go to the Permalinks tab on the WordPress dashboard and change the format to:

http://www.yoursite.com/sample-post/

6. Test it by searching for a couple of your posts in Google or other search engine. The result should resolve to the new title of the post. You did it!

7. It’s a good idea to re-hide hidden files on your local machine so you don’t delete or alter one of these vital files by accident. To do this on Mac, just go into Terminal and enter the same instruction as previously but this time end it with “NO” instead of “YES”:

defaults write com.apple.Finder AppleShowAllFiles NO

UPDATE: Years later I find myself setting up a wordpress.com blog and find this option isn’t available; for this free platform you are stuck with the http://www.yoursite.com/2013/05/sample-post/ format with the date in the middle of the permalink. This is true even if you pay for one of the available upgrades, to Premium or Business.

One thought on “How (and why) to change your WordPress permalink structure”

  1. Hey, thanks for taking the time to explain this is layman’s terms. I did read Joost’s description but it was a level above my newbie mind. Yours is much easier to understand. I’m setting up my own WordPress blog so this is super useful!

Comments are closed.