Quick and dirty htaccess rewrite for Lighttpd

Writing this post and am getting ready to hide behind strong walls, since mostly lighttpd is meant to fly light, or serve faster without the bloat and dynamic flexibilities. But certain situations may occur where one may have to forget the religion and behave sensibly. For a major project which was collaborated by different teams of our spread out offices, one part was developed by a team who were more exposed to benefitting the furls (friendly urls), by using apache rewrites. The bang off was detected only at the last moment of roll out to the beta deployment at client environment.

The environment was running on multiple Virtual Box machines housing lighttpd, fcgi and php. There was no time for an R&D to get the lighttpd rewrites, and it would be ages before I reload all of the lighttpd farm. So the quick and easy way was to add some regexp rewrites to the already dynamic 404.php. I am sharing this for the benefit of my readers as well as for bein indexed for the rest of my life.

 * php workaround for lighttpd, incase rewrites are complicated
 * server.error-handler-404 = this.file in lighttpd conf
$rewriteif = array(
"deadline/(.*)/(.*)" => "index.php?mod=dynpage&req=deadline&sitename=$1&productname=$2",
"specifications/(.*)/(.*)" => "index.php?mod=dynpage&req=specifications&sitename=$1&productname=$2",
"mainpage/(.*)/(.*)" => "index.php?mod=dynpage&req=mainpage&sitename=$1&productname=$2",
"pdfpage/(.*)/(.*)" => "index.php?mod=dynpage&req=pdfpage&sitename=$1&productname=$2",
"pdfdeadlinepage/(.*)/(.*)" => "index.php?mod=dynpage&req=pdfdeadlinepage&sitename=$1&productname=$2",
"camera/(.*)/(.*)" => "index.php?mod=dynpage&req=camera&sitename=$1&productname=$2",
"material/(.*)/(.*)" => "index.php?mod=dynpage&req=material&sitename=$1&productname=$2",
"otherart/(.*)/(.*)" => "index.php?mod=dynpage&req=otherart&sitename=$1&productname=$2"
$rewriteif as $reg => $tag){
preg_match("@$reg@"$_SERVER['REQUEST_URI'], $m)){
$file$vals) = explode('?'$tag);
$vals str_replace('$1'$m[1], $vals);
$vals str_replace('$2'$m[2], $vals);
header("HTTP 1.1 Not Found"404);