Here at Reevoo we (like many others) use Apache as our webserver of choice and with this comes the venerable mod_rewrite.
Mod_rewrite can be used for a lot more than just redirecting pages though, you can use it for forward and reverse proxying, redirection and url rewriting based on various factors such as the HTTP host or request uri. However there are myriad ways in which to shoot yourself in the foot!
We love testing, so when an article about testing mod_rewrite rules using Test::Unit by the guys at Viget Labs popped up in my feed reader I quickly popped round to take a look.
Using the redirect tester you can easily define shoulda style tests by doing something like this
class ReevooRedirectTest < HTTPRedirectTest
self.domain = 'www.reevoo.com'
should_redirect '/decidewhattobuy/blog', :to => '/decidewhattobuy', :permanant => true
should_redirect '/blog', :to => '/decidewhattobuy'
end
This is very cool and makes working with mod_rewrite much less painful than it can be!
The original code is a series of gists hosted on the vigetlabs github page and to make them easier to use and manage I packaged it up as a gem, which you can install as follows:
sudo gem sources -a http://gems.github.com && sudo gem install shadowaspect-http_redirect_test
and use it in your code like this:
require 'http_redirect_test'
have fun!
