Apache sneakiness.

This is a story about system administration. It’s about a system, and it’s administration. In particular, it’s about configuring up Apache to do some magical rewriting of URLs so that a site we’re working on can translate /foo/bar into /foo.php?item=bar . Ready to journey with me? Let’s go…
I’m running XAMPP on clipper – it’s a very nice ‘prepackaged’ solution for developing LAMP-like applications on Windows. It includes MySQL, Apache, PHP, and a handful of other tools, and it makes building and testing apps under PHP quite tolerable under Windows.
What we were doing sounded like a fairly simple application of mod_rewrite. The specific function was whipped up by Tim, and I SVNupped it to clipper – and it didn’t work. I was getting something that basically said “you’re running this script without initializing it properly”.
It got more and more bizarre, as I realized that in fact, mod_rewrite wasn’t even loaded in my Apache install, but it was obviously doing some bizarre bit of rewriting. hits to http://localhost/foo/bar/baz would not give a 404, but would attempt to run the script ‘foo.php’, passing in parameters.
I spent a good 2 hours S’ingTFW on issues with XAMPP, PHP5, Apache, mod_rewrite – grepping through a few dozen configuration files (oh, sorry, ‘find’ing – windows equivelent of grep. Which, incidentally, sucks.). Nothing was coming together.
Eventually I fell to the #apache channel on FreeNode, and sang my tale of woe to them. I stumped several of the more knowledgeable folks there for a good half hour (“it’s a mod_rewrite, but you don’t even have the module loaded. Huh”), when, just like a good mysterious western, a previously silent voice in the back piped up, and uttered one word.
“Multiviews”
It was the word that was to haunt me for… 15 minutes. This is an option that I’ve seen countless times in configuration files, but really had no idea what exactly it did. I metaphorically dragged out the Apache 2 reference docs, and, blowing the dust of the pages, read about Multiviews:

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client’s requirements.

I was stunned. This option, as Tim put it, had the equivalent effect of… “the server closes its eyes and THROWS DARTS AT THE FILESYSTEM until it finds something that looks good.”
Naturally, my vhost had it enabled in it’s Options line. Taking out Multiviews, hupping the server, and lo, no more magical mystery rewriting!
I’ve been administering Apache installs since before it was called Apache, and I’ve never hit this problem before. Let’s hear it for learning experiences! :-/

About

A wandering geek. Toys, shiny things, pursuits and distractions.

View all posts by

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.