Url rewriting refactoring

http://www.esigate.org/mantisbt/view.php?id=285