Your application looks messed up, Which framework are you using or if not who coded this ?
Basically rewrite will be a lot easier, if you could modulate the pages, like category.php?name=name1 , This would be much easier to generate rules and generic rules can be generated.
If you follow up...