Redirecting/prettifying URLs with .htaccess

Everyone that has ever tried to use mod_rewrite with .htaccess files, to get a nice url or even just to redirect to a subdirectory without the user knowing it, have probably been swearing, biting, hitting and cried over; the regex, the syntax, the lack of (human-oriented) documentation and so on.

A friend of mine and I tried went through several of these phases yesterday; the goal was easy:

get http://localhost/ams/anything.php to redirect to http://localhost/ams/qsys/anything.php

With localhost being variable and offcourse http://localhost/ams to redirect to http://localhost/ams/qsys/

We tried several approaches with increasing complexity. And cried, sweared, killed apache and so on. The apache test server was installed locally on windows plattform (xampp) so the first glimpse of light was when we realized the /apache/logs/error.log and the setting for apache; LogLevel debug. This resulted in some debug information on what the .htaccess made apache do. After realizing the plain .htaccess in /ams/.htaccess, containing something like this;

RewriteRule ^(.*)$ qsys/$1 [L]

Made apache reach a recursive hell into qsys/qsys/***. But nevertheless, at the first call it did exactly what it was supposed to do. So. How to stop it. The solution, easy, probably not a silver bullett, but works;

A .htaccess in /ams/qsys/.htaccess with RewriteEngine Off

Like a deux ex machina it worked!

So, to all out there that have reach insanity over mod_rewrite and nice urls. Do it simple! Hope it works out well:)