3 min read
Two Wordpress plugins you <i>don't</i> need and <i>shouldn't</i> use
Two popular WordPress plugins kill a flea with an elephant gun, when a few lines in your .htaccess file do the job better.
I immediately want to apologise to the authors of these plugins but the fact remains, sometimes someone comes along offering to kill a flea with an elephant gun, and well... it's time to just come right out and admit that was the wrong approach.
The two offending plugins on my hitlist for today are the Permalink Redirect plugin, which Ronald Heft (cavemonkey) and others have listed as a Top Ten Wordpress plugin, and the no-www plugin, by no less a luminary than Matt himself (aw crap can you get away with contradicting da man?!).
Both these plugins do with an elephant gun what Apache can do with a pea-shooter. Yep... I'm speaking again of mod_rewrite and a .htaccess file. My point is simple enough... use the right technology for the right problem; always keep things as simple as possible.
A quick and obvious point: if you can't use mod_rewrite because your host doesn't turn that on in Apache... get another host. If you're on IIS you can get a host to achieve something similar with an ISAPI filter (that's really pretty cool, and one I've stress tested under load and checks out OK), but it's fair enough that many Windows Server hosts will need some convincing to install that. But... if you're genuinely left in this "can't use mod_rewrite camp" then I guess the plugins are fair enough. What else can you do?!
But now for the rest of us...
I've already posted about how to use mod_rewrite to forcibly include or exclude a www in your domain (URL). You'll notice on my site that if you remove the www, it gets stuck back on. So we'll move on.
And the other plugin? Cavemonkey is absolutely right in explaining the importance of the function of this plugin:
One of the fatal flaws of WordPress is that URLs with a trailing slash are the same as URLs without. This is bad for your stats since one page can show up under multiple URLs, and it’s also bad for search engines who may duplicate your pages in their results.
No arguments there. Just a question of how it's done. Here are the two lines to add to your .htaccess file to achieve the same thing in a far simpler, lightweight kind of way:
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
I add this mod_rewrite rule under the one that deals with the "www" and together they sit above the standard Wordpress rules, and look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.alistercameron.com$ [NC]
RewriteRule ^(.*)$ http://www.alistercameron.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
</IfModule>
It's not rocket science, and it does assume you can edit a file via FTP, but that's all there is to it.
If you get something wrong, yes, mod_rewrite can kill your site in one fell swoop, but if you quickly restore the earlier version of the file and check your changes you'll be fine.
Don't you feel so much better now? We'll leave the elephant gun for another day... After all, it was just a couple of fleas :)
mod_rewrite, htaccess, wordpress, plugin, wordpress plugin, redirect, isapi, url rewrite


