mod_rewrite misinformation

rewrite.jpgI wrote a book about mod_rewrite. Perhaps you have a copy. If so, thanks.

Additionally, I spend a lot of time on IRC (freenode.org, #httpd) answering mod_rewrite questions. And I speak at various conferences, frequently on the topic of mod_rewrite.

mod_rewrite isn’t in fact, terribly difficult. However, it is made more difficult by two factors.

First, regular expressions are universally perceived as being difficult. Thus, even people who haven’t even tried to learn about them already *know* that they are difficult, because someone else communicated this dread to them in a weird tribal knowledge rear-brain kind of way.

Second, and perhaps more damaging, is the ENORMOUS quantity of misinformation that exists online about mod_rewrite. If you search for a rewrite recipe to do X, you’ll find a hundred of them, and at least 75% of them will be Just Plain Wrong, while 20% of them will be either misleading, or confusing, or actually work, but do it in such a way that enormously obfuscates things to the point that nobody can understand what’s actually going on.

The other 5% will make the observation that the task in question doesn’t actually require mod_rewrite, but that there’s another, more efficient and simple, configuration directive that does exactly what is being requested. Such as Redirect, or SetEnvIf, or Alias, or UseCanonicalName.

I became interested in mod_rewrite primarily because of regular expressions. Having read Jeffrey’s marvelous book from cover to cover back in the first edition, and using regex extensively in Perl, I figured, how hard could it really be? The secret answer is, not very hard at all. But since people go pretty far out of their way to make it hard, I’ve been guaranteed a speaking spot at any conference I want to submit a paper to, because people say, Oh, mod_rewrite is HARD!! Lucky me.

So, once again, a huge thank you to Ralf for creating this beast.

I will now resume my eternal quest to find and gently correct all of the bad mod_rewrite examples out there on the web.