changing of the guard

After quite some experimentation, much of it fruitless, that has resulted in a mass tug-of-war with Wordpress and it’s infernal re-write rules, the structure of the ‘foo has changed. This has primarily been driven by a fundamental flaw in Wordpress that will likely never be addressed, as it’s simply not considered a “problem” to begin with..

Whilst I am not at all pleased with the final result, it’s the closest I can come to a workable solution, that scales well and will be as ‘fluff’ free as I can make it.

It means I have to go back to using pages for semi-static content, rather than using a fluid rewrite rule set that blurs the lines to make pages and posts interchangeable. Thus, the resulting changes to the overall structure, are :

  • links to posts are now formatted as /year/month/postname,
  • categories are now assigned with a /meta base and are still used to ’structure’ and finally
  • tags are still in use throughout to describe and link related content.

As I have noted previously using a /%category%/%post% permalink structure wasn’t as smooth-a-sailing as one would expect to believe. One of the reasons for using such a structure is that it reduces permalink ‘fluff’ - the downside is that Wordpress still enforces the category base rule.

So whilst one can have nice short URIs for posts, the categories end up having a redundant component. And really, “/category/journal” isn’t any more descriptive than “/journal”. Why? .. ultimately the category base doesn’t help describe the content at all and pretty much just gets in the way. It’s also disinjenious as one can end up with crazy non-logical uri structures as:

  • http://www.smackfoo.com/meta/journal/page/2 for category archives, yet
  • http://www.smackfoo.com/journal/post_name as individual entries.

Whilst Wordpress has become increasingly more custom friendly, with more dynamic functionality being added as time progresses, it does very show that the re-write engine has not seen much action since it became an internalised process. Really, the above should be merged into one option, that allows one to select a custom URI structure that keeps both category archives and posts in some semblance of logical association.

Whilst many have tried to remove the category base the results are very hit and miss, with RSS feeds and pagination ending up being the vanquished, due to the aforementioned category base enforcement.

In every case and every plug-in I used to try and dispatch our dear friend the category base, it caused catastrophic failures in re-writes for RSS feeds and pagination to name but a few, in some cases the entire structure broke down. I had noted an increase in 404’s of late and after some serious groking, I can attest that much of this is down to the unreliable way Wordpress handles custom URI options.

Rather than continue to fight a battle I cannot win - I’ve made use of some related material on doing nifty shit with re-write rules. I wanted to keep the old URIs for posts intact, as is, yet have all new content use the new URIs, because whilst some might say cool uri’s never change I am very much of the opinion that change is inevitable — it’s not how one resists change, but how one handles the inevitability of it that matters. Thus the following became invaluable:

“I ended up creating a simple plugin that uses the “generate_rewrite_rulesâ€? action hook to add additional URI rewriting rules to the internal set used by Wordpress to resolve each URI.” #

And the code used?

< ?php
function add_permalink_style($rewriteobj) {
    $extra_rewrite = $rewriteobj->generate_rewrite_rules(’/%category%/%postname%’, EP_PERMALINK);
    $extra_rewrite = apply_filters(’post_rewrite_rules’, $extra_rewrite);
    $rewriteobj->rules = array_merge($rewriteobj->rules, $extra_rewrite);
}
?>

Result? .. a simple and elegant solution — older structures remain intact as is, without 301 redirects and silly “you have to update your links” shout-outs, that never, ever, work. Old stuff keeps working, new stuff keeps working. Seamlessly. The way it should be.

Despite recent advances in Wordpress, I am saddened to say that the whole mess that is enforced re-writes, has seriously made me question the longevity of using an engine that has very ’specific’ re-write rules. And because of the path taken — I am entirely unconvinced it will be rectified, as folks start resorting to tagging (which I also use) and other meta structures to try and get away from categories in their entirety.

If it cannot adapt to change, it will be, eventually, left behind by other platforms that rise to the occasion. One can only hope native tagging replaces categories to provide a simpler framework - allowing those who still want to categorise content, the freedom to do so.

≡ This is a journal entry relating to the topics of , , , , .

Brendan Borlase is a Systems and Network Administrator living in Adelaide, Australia, having lived, worked and breathed Information Technology for over 12 years. Learn more.

Feedback is encouraged. If you would like to read more, consider subscribing to the regularly updated RSS Feed.