January 7th, 2007 | No Comments
Changing Your Wordpress Permalink Structure
There’s been a couple of times where I’ve wanted to alter the permalink structure of my Wordpress blogs after having the site running for a period of time.
The main issue here is to ensure that all links into your pages (most notably from search engines, but possibly from within your site too) redirect to the new addresses corectly, and don’t show any nasty 404 errors.
The best way to do this is with “301 redirects”, which tell the search engines that the page has moved permanently, and after a while they should show the new page in their results pages (for Google this can be a reasonably quick process if your site gets crawled regularly, for other search engines it seems to take a longer time for them to catch on to the redirects).
The way I achieve this is through editing the .htaccess file, but rather than typing in all of the new addresses by hand, I run a script to produce all of the necessary 301s, and them copy and paste them in to the file.
Wordpress has several permalink structure options, in my particular case I wanted to go from just using the post name in the URL to adding the post ID into the URL too.
The script in the following link produces the list to change the permalinks from:
/%post_name%/
to:
/%postid%/%post_name%/
The script: /code/wordpress-permalink-redirects.txt
Once you’ve run the script, copy and paste the output into your .htaccess file - this can be done through the Wordpress admin panel, but be careful not to overwrite anything that is already in there.
By playing with the results from the script you should be able to achieve your desired structure (if you need help with a particular structure, why not let me know in the comments below).
One thing to look out for is that any pages that do not need redirecting may appear in the list - if so, delete them from the list or your .htaccess file. Also, hundreds and hundreds of entries in your .htaccess file may slow down the performance of your server, so it’s something to keep an eye on.
Given time, this would be a simple procedure to turn into a Wordpress plugin (if it doesn’t already exist, if so, please let me know.) in which you could specify the structure you wish to change to, and the plugin would automatically write the list to your .htaccess.
