<?php
//What URI was I accessed as?
$uri $_SERVER['REQUEST_URI'];

//Remove everything except the last section
$uri explode("/",$uri);
$uri array_pop($uri);

//Convert to lower case (as in Wordpress)
$uri strtolower($uri);

//Remove the post id from the beginning of the post
$uri explode("-",$uri);
array_shift($uri);
$uri implode("-",$uri);

//Remove the extension (.html)
$uri explode(".",$uri);
array_pop($uri);
$uri implode(".",$uri);


// Now send a 301 Moved Permanently and the new location
header("Location: /$uri",TRUE,301);
exit();