WordPress Permalinks
Posted in Software on August 21st, 2009 by Noldorin – Be the first to commentIn the process of setting of setting up my new blog, I quickly realised that by default WordPress was displaying posts and pages using query strings in the URLs, quite in contrast with the pretty URLs I was expecting from my experience hosting on WordPress.com.
To give example, in contrast to
/blog/?p=123
which was the form being shown, I was desiring something more like
/01/10/entry-title-here
Not such a terribly important matter in the scale of things; yet aesthetics is usually a worthwhile pursuit, so why not with URLs too? Moreover, the URLs then become hackable in this form.
Like many other features of the WordPress system, pretty permalinks are not enabled as default, but can be configured with a bit of effort. In this case, it required more than a bit of effort…
The problem here is caused primarily by the fact that WordPress is designed to run best on an Apache server, and not an IIS (Windows) server. In fact, pretty permalinks generally work using a .htaccess file that uses the mod_rewrite engine. Indeed, this is the file WordPress generates by default. Saying this, it is not much more difficult to confiugre IIs 7 to do the URL rewriting – the WordPress Codex page on Using Permalinks does in fact detail exactly the code required in web.config. IIS 6 is another story, unfortunately. As far as I know, many shared web servers provide the ISAPI Rewrite tool, as does my current one. Version 3 supports Apache-style .htaccess files; but alas, version 2 is all that I have available, and is probably the more widespread one at present.
After a fair bit of messing around with the httpd.ini file in the root directory of my website, I finally managed to replicate the URL rewriting functionality otherwise available on Apache servers. It’s not quite as elegant as the standard .htaccess method, but it seems to be both short and efficient. A word of warning: it has only been tested with the latest version of WordPress (2.8.4), so I cannot guarantee complete success on other versions.
[ISAPI_Rewrite] UriMatchPrefix /blog/ RewriteCond URL (?!wp-.*).* [O] RewriteCond URL (?!license.txt$).* [O] RewriteCond URL (?!xmlrpc.php$).* [O] RewriteRule .* /blog/index.php [L]
Simply past the above text into a file named httpd.ini, copy it into the root directory, and you have your pretty permalinks (providing, of course, that you have set the option in Settings > Permalinks of the admin interface.)