Making your WordPress Permalinks tidy

I really like clean URLs.  For example, I far prefer a URL like http://en.wikipedia.org/wiki/Tidy over something like http://www.gravitycomputing.co.nz/cgi-bin/gen.pl?id=4&category=M753n&style=gw3b (don’t even try it, that’s a fake link).  For me, it’s a matter of ‘the tidier the better’, because the less in the URL, the less people have to remember when they try to find things again.

Until last night, the permalink structure on this site was something like:  http://blog.gravitycomputing.co.nz/index.php?p=123.  That’s not too bad, but it really doesn’t tell people what they’re looking at.  So I changed it to one of the other builtin WordPress permalink structures:  http://blog.gravitycomputing.co.nz/index.php/2011/05/sample-post/.

Ok – this is a bit more descriptive, but other than that, it really sucks!  I wanted something much simpler.  Here’s how I did it:

1)  In the Permalinks settings in WordPress, select “Custom Structure”.  I went with a custom structure of /%postname%.  This gives me basically no extra fluff.  It also means that I can never duplicate a blog title, but — that’s okay with me.

2)  Unfortunately, this didn’t work on its’ own.  I also needed to modify the .htaccess file, to rewrite the address so that my web server knows to direct these pages to WordPress’s index.php.  I’m not very good with the mod_rewrite rules in Apache, but I got there, thanks to Marco De Cesaris.  Marco has posted just this thing on his blog, here:  http://www.marcodecesaris.com/how-to-remove-the-indexphp-from-the-pretty-permalink-in-wordpress-25x-27.html

All I had to do was to paste this into the .htaccess file in my WordPress directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Voila!  Super-tidy URLs!  Like this one:  http://blog.gravitycomputing.co.nz/recent-events-at-gravity

Thanks Marco!