Do You Need Permalink Redirect?

Via CaveMoney50, Alister Cameron wrote about Two WordPress Plugins You Don't Need and Shouldn't Use. Number 1 on the list: Permalink Redirect, closely followed by Matt's No-WWW plugin. Actually, since release 0.7, Permalink Redirect can already redirect on hostname mismatches, which makes No-WWW obsolete. That means, my Permalink Redirect is the Number 1 WordPress Plugin that you do not need and should not use! Bwahahaha!!!

While I thoroughly enjoyed my position being the Number 1 resource-wasting WordPress plugin, I also agree with Alister -- why code it in PHP when your web server can do it faster for you? But hang on?! That hack requires access to .htaccess file which not everyone has access to. For example,

  1. Hosting companies do not allow you to override options in .htaccess.
  2. Alternative web server is used like Lighttpd, Nginx or (heaven forbids) IIS.

Then you should obviously change your hosting company. Maybe not Media Temple, whose (gs) product is causing grief wherever I read about it. This blog is currently hosted on NearlyFreeSpeech.NET (which I reviewed here) -- maybe you may want to consider it.

Actually, there are indeed equivalent rewrite rules available for lighty and Nginx. Here is one for lighty (a bit flaky because lighty lacks file-exists condition):

server.modules += ("mod_redirect")

$HTTP["host"] == "example.com" {
  url.redirect = ("^/([^.]*[^/])$" => "http://example.com/$1/")
  server.error-handler-404 = "/index.php"
}

$HTTP["host"] == "www.example.com" {
  url.redirect = ("^/(.*)$" => "http://example.com/$1")
}

Nginx? No problem either.

server {
  server_name www.example.com;
  rewrite ^/(.*) http://example.com/$1 permanent;
}

server {
  server_name example.com;
  if (!-e $request_filename) {
    rewrite ^/([^.]*[^/])$ http://example.com/$1/ last;
    rewrite ^.*$ /index.php last;
  }
}

The idea is -- if all you need to do is ensuring a trailing forward slash in URL, then doing it as a plugin inside WordPress might not be a good idea if you wish to get the maximum performance from your WordPress site. Instead, your web-server can send back a redirect response much faster without a single line of PHP gets executed. This is especially true when Permalink Redirect is only tested after some SQL queries have been executed. So if someone linked your site to Digg without the trailing slash, got pushed to the front-page, and 10,000 visitors followed that URL in within an hour -- your blog post will be loaded from MySQL at least 20,000 times if you have Permalink Redirect installed.

And the co-habitants on your $5 per month shared hosting will absolutely hate you.

So if you do not want to be hated by your hosting company whenever you got dugg, then you probably don't need and shouldn't use my Permalink Redirect plugin.

Unless you are like me, who will never get dugg no matter how hard I've tried, don't care what the hosting company says, have no desire to touch the .htaccess file, and sometimes use permalink structure without a trailing slash, then you are free to stick to my resource-wasting plugin :)