Tag Archives: mod_rewrite

Come see me at ApacheCon NA 2014

In April I will be speaking at ApacheCon North America in Denver, Colorado. I’ve had two talks accepted:

Configurable Configuration is a talk about some of the new shiny configuration syntax available in Apache httpd 2.4 – stuff like the If/ElseIf/Else syntax in configuration files, the new expression evaluation engine, and mod_macro for scriptable configuration blocks, for starters.

Demystifying mod_rewrite will drag you kicking and screaming from being a mod_rewrite newbie to being a mod_rewrite expert. You don’t dare miss it.

We’re also presenting two whole days of Apache http server content – code-named “httpd.conf” – get it?

And there’s ten tracks of amazing content across more than 70 projects from the Apache Software Foundation.

Register at na.apachecon.com by March 14 to get the early rate.

mod_rewrite and ignorance

For the last week or two, I’ve been using Twitterrific. One of its features is that you can watch for all tweets that contain a particular word or phrase. So I’ve been watching ‘mod_rewrite’. The following graph shows the rough distribution of those tweets.

It’s distressing to me, as something of a recognized expert on the subject, to see the vast amount of information online about mod_rewrite which is inaccurate, inefficient, or just plain wrong. But people are clearly hungry for any scrap of mod_rewrite info that they can get, since every time another misinformed tutorial is posted, 30 people retweet it as gospel.

Now, some could claim, very justly, that we brought this on ourselves. The documentation is frightening, and announces in the first paragraph that this is not for mere mortals, and has been largely unchanged for over ten years. We’ve recently done a complete overhaul of the docs, but it might just be too late.

And, of course, another huge force is at work here. Yes, the SEO industry. No, I will not engage you in the debate about whether all so-called “SEO professionals” are snakes and liars. A significant portion of this industry thrives on misinformation and impossible-to-fulfill promises. And many of these folks equate “SEO” and “mod_rewrite”, thus indicating a complete lack of understanding of both.

Between these two forces, there’s a huge thirst for useful mod_rewrite tutorials, both by people with legitimate need for mod_rewrite, and people who have been told, inaccurately, that they need it. And, unfortunately, for years the Apache docs haven’t done that. They haven’t offered the examples that people are actually looking for, and they’ve had that dreadful “ABANDON HOPE” across the front arch.

So, we’re working hard to rectify this with the new docs which will include lots of examples, and hopefully address the questions that you’re actually asking. But, alas, the nonsense tutorials keep springing up, so perhaps we need some active way to address those, tell you why they’re mistaken, and perhaps encourage the authors to correct them in useful ways that will result in the spread of true, accurate, efficient mod_rewrite information, and less of this ridiculous myth that mod_rewrite is a big scary monster.

mod_rewrite docs rewrite at ApacheCon

The plan, (assuming I don’t get sidetracked on a million other things, which is what usually happens) is to do a major overhaul of the mod_rewrite documentation during the hackathon at ApacheCon. Please speak up if you have specific comments or recommendations. So far, the outline is something like this.

1) A couple of years ago, I split the “Rewrite Guide” into basic and advanced. This was ill-advised, and the division was stupid. Now it’s just harder to find stuff. Going to re-merge those, and then try to do a division based on topic, rather than difficulty, since that’s not a particularly useful concept.

2) Rewrite cookbook, divided into categories of, perhaps:
a. redirecting/remapping
b. controlling access
c. when not to use mod_rewrite (aka ‘mod_rewrite is obsolete’)
d. advanced features

3) Scrap the inscrutable examples. Both the guide and the formal docs are littered with examples that either never happen in the real world, or are done better using some of the built-in functionality of other modules like mod_alias and mod_dir. Scrap those examples entirely, rather than continuing to try to make then scrutable.

4) Rewrite Flags documentation. Started this years ago, and never really finished it. Also, needs to be updated to include the new flags that have been added in 2.2 and trunk.

5) General grammatical overhaul, hopefully with help from Noirin, who has better grammar than all the rest of us put together. (Actually, that’s the problem – it was written by all of the rest of us put together, resulting in a mish-mash of styles and voices.)

6) A document about (so-called) S.E.O. uses of mod_rewrite, discussing both the techniques that can be used, and the misinformation that tends to drive the desire to use those techniques. This needs to be handled carefully, because there’s a tendency to simply state that all SEO is snake oil – which much of it is – and ignore the topic entirely. But, folks are going to do this stuff whether or not we approve, and it’s better if they do it well. At least, that’s what I think at this particular moment.

2c, above, is both about stuff that you shouldn’t do with mod_rewrite at all, and also some of the new features in 2.2 and trunk that make mod_rewrite unnecessary.


The Apache Web Server version 2.2.12 released today, including the following nugget of joy:

‘discardpathinfo|DPI’ (discard PATH_INFO)

In per-directory context, the URI each RewriteRule compares against is the concatenation of the current values of the URI and PATH_INFO.

The current URI can be the initial URI as requested by the client, the result of a previous round of mod_rewrite processing, or the result of a prior rule in the current round of mod_rewrite processing.

In contrast, the PATH_INFO that is appended to the URI before each rule reflects only the value of PATH_INFO before this round of mod_rewrite processing. As a consequence, if large portions of the URI are matched and copied into a substitution in multiple RewriteRule directives, without regard for which parts of the URI came from the current PATH_INFO, the final URI may have multiple copies of PATH_INFO appended to it.

Use this flag on any substitution where the PATH_INFO that resulted from the previous mapping of this request to the filesystem is not of interest. This flag permanently forgets the PATH_INFO established before this round of mod_rewrite processing began. PATH_INFO will not be recalculated until the current round of mod_rewrite processing completes. Subsequent rules during this round of processing will see only the direct result of substitutions, without any PATH_INFO appended.

It might also be handy, some day, to have a [DQS] flag that discards the query string explicitly, rather than having to do silly tricks to make it disappear.


I don’t remember exactly when I started doing mod_rewrite stuff. I remember why. I noticed that more than half of the questions on #apache were about mod_rewrite, and I made a decision to become the expert on it. I was already very familiar with regular expressions, since I was a Perl programmer at the time, so I figured it couldn’t be very difficult.

I determined pretty early on that the biggest difficulty with mod_rewrite was that people were afraid of it. In particular, they were afraid of regular expressions. And there’s plenty of things floating about reinforcing this fear, not least of which is the mod_rewrite documentation itself.

So, now, several years on, I have a book about mod_rewrite, and in about 10 minutes I’ll be giving Yet Another conference presentation about mod_rewrite, which is nothing more than an affirmation that this isn’t hard (after all, I mastered it) but that there’s still a lot of people who need help with it.

Online mod_rewrite training

I’m considering doing online training on mod_rewrite, based on the book and the training class I’ll be doing next week. I’m still not sure what I should charge, or how I would go about marketing it. But I’ve got Moodle installed, and I’ve got a course outline started. So if you’re interested in taking a mod_rewrite course, let me know, and I’ll try to figure out what I’m going to charge.

mod_rewrite class

I’ll be teaching a three-hour mod_rewrite training class at ApacheCon US, in Atlanta, Tuesday November 13th. There’s another day of training classes before this, on the 12th, and then the main conference follows, the 14th-16th. If you’re looking to get up to speed on mod_rewrite in a hurry, this is the place to be. We’ll be covering everything from basic regular expression syntax up through esoteric tricks with RewriteRule and RewriteMap and the whole thing, so come early, stay late, bring your laptop, and get ready to become a mod_rewrite wizard.

Class details here.

Conference website here.

Pricing and registration information here.