Interesting new Apache features

A couple of hacks I’ve made to Apache in the week or two before starting this blog merit a mention here.

The first fixes an apparently-common problem encountered by people using DAV with https hardware. The solution: add regular-expression rewriting capability to mod_headers. The DAV problem is now fixed by simply rewriting https:// to http:// in the Destination: header. More complex mod_rewrite-like header manipulation is also possible, and might be useful in, for example, mass-virtual-hosting configurations.

The second interesting change is one that’s been on the to-do list for a long time. I’ve just added SQL database-based lookups to mod_rewrite‘s rewritemap feature, using Apache DBD.

Posted on October 16, 2006, in apache. Bookmark the permalink. 13 Comments.

  1. Nick, doesn’t specifying the https:// prefix in the ServerName directive fix the problem? I thought it did but do not have an adequate server handy to test. The ServerName has this capability in both trunk and the latest 2.2 release, and it was added especially for the case of an external SSL processor.

  2. ServerName deals with Server-generated URLs. But this DAV problem involves Client-generated URLs. So it’s the “RequestHeader” directive, not “Header”, that matters here (though of course the patch works equally for both directives).

  3. The RewriteMap SQL thing is the bee’s knees. When I saw the diff come across, I giggled like a school girl. This is *awesome*!

  4. I’ve been thinking about using mod_rewrite with dbd since the original apr dbd code was committed – nice to see someone doing the work 🙂

  5. DrBacchus – Does this mean you need to update your book and publish a second edition?

  6. The book was painful enough the first time that I think I should wait at least another year before a second edition.

  7. I’d be interested in seeing some sample code with RewriteMap using SQL through DBD.

  8. FYI – I’m trying out the mod_rewrite + mod_dbd functionality. Good stuff! Haven’t gotten it to work yet, it keeps looking for a file. 😦

  9. I was able to get it functioning, but with some very odd behavior. I wrote up my experience here:

    It seemed I had to start the server with just the DBD conf, then uncomment the RewriteMap, then uncomment the RewriteRule. If I tried to start with all three active, it would flail. I tried to use strace for awhile, and thankfully before I threw in the towel for the night I discovered gdb, so that will be my next tool for figuring out what’s up with these two modules playing nicely together.

    Surprises me to find that your post is almost a year old! I’d be curious to learn what has happened in the code (if anything) since then.

    Thanks again!

  10. Albert – thanks for the comments. I had a look at your writeup, and nothing springs to mind as a likely explanation for your problems, apart from the fact that DBD/rewritemap is breaking new ground. I’ll have another look as and when I revisit this function.

  11. Thanks Niq, I haven’t given up yet. I did try updating to the latest subversion with no changes. I’ll be back if I make any progress.

  12. OK, I found some reliably reproducible behavior. If I start the server with the relevant RewriteMap, RewriteConf, and RewriteRules off, the server starts, and then I can uncomment them, and restart it and it works. BUT, if I stop the server and then start it with the rewrite rules still active, it segfaults. Any idea why it would work when restarting it as opposed to simply starting it? I tried using gdb but it only tells me that it segfaults due to some memory issue.

  1. Pingback: apr_dbd_freetds driver « niq’s soapbox

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: