The Definitive Guide to Apache mod_rewrite (A Book Review)
Posted by Neil Crosby on March 12, 2006 05:50 PM
A couple of weeks ago, I was sent a review copy of “The Definitive Guide to Apache mod_rewrite” by the lovely people at Apress. The book promised to be the be-all and end-all guide to the mod_rewrite module, and overall it succeeds.
Rich Bowen (also author of Apache Server Unleashed, The Apache Administror’s Handbook and The Apache Cookbook) clearly knows his stuff and guides the reader through the module with ease, introducing key concepts as he goes. There are times, however, when to me the book feels as though it is aimed just a bit too much at the beginner to be a truly definitive guide to the module. This doesn’t mean I don’t like the book though - I think it’s fantastic and it really should be on everyone’s reading list if they’re seriously wanting to learn how to use mod_rewrite.
The book assumes absolutely no prior knowledge of the mod_rewrite module, and is broken up into an easy to digest 12 step programme which will get you using the module in no time at all. Here’s how those chapters look:
An introduction to mod_rewrite
Here, Rich talks about what mod_rewrite is and why on earth you’d decide to use it at all. He also starts hammering home the gospel that mod_rewrite should not be used all the time - there are plenty of circumstances where it makes much more sense to use something else.
Regular Expressions
This second chapter is very useful if like most people, you’ve never used a regular expression before. Even if you feel you’re pretty handy with the regex spanner in your toolbox, it would probably be a good idea to skim this chapter and maybe pick up a pointer or two that you’d not known about before.
Installing and Configuring mod_rewrite
If you’re runnning your own server then this is going to be of interest to you. If, on the other hand, you’re just running a website on a shared server then it probably isn’t. It does show you a couple of ways to test whether mod_rewrite is installed and working though.
The RewriteRule Directive
Ah, here we go - chapter four is where we start actually doing something with mod_rewrite! The
RewriteRule
is looked at in depth here, and a big chunk of the chapter is given over to the various flags that can be used with it.The RewriteCond Directive
Chapter five looks at how we can use logic to determine whether or not a
RewriteRule
should be executed. It’s only ten pages long, but the content is incredibly valuable.The RewriteMap Directive
Again, this chapter is not going to be a huge amount of use to people who run their websites in a shared environment and don’t have access to the Apache configuration file, since
RewriteMap
cannot be used within a .htaccess file.Basic Rewrites
Half way through the book, it finally gets onto some meaty examples of how to use mod_rewrite.
Conditional Rewrites
Continuing on from Chapter seven, in this chapter we get a good section of examples of using
RewriteCond
to determine whichRewriteRule
s should be run.Access Control
The examples start coming thick and fast now, as this chapter shows you how to use mod_rewrite to control access to your website. More importantly, it also shows you when you shouldn’t use mod_rewrite to do this.
Virtual Hosts
Another chapter that’s going to be of no use to those people who are running their websites in a shared environment, this one will be of great use to those systems administrators who have to look after hundreds or even thousands of virtual hosts on a day to day basis.
Proxying
This chapter helped me out at work just after I read it. Essentially, it shows you how to use mod_rewrite as a proxy to transparently redirect to multiple back end servers for load balancing and the like.
Debugging
The final chapter shows you where to go when all else fails and things don’t work quite the way you expected and teaches you how to use the
RewriteLog
.
All in all, I think that “The Definitive Guide to Apache mod_rewrite” really is that - a definitive guide that will get people off to a fantastic start with the swiss army knife of Apache modules. A definite must buy if you’re going to be doing anything with mod_rewrite.