The key is kungfu. A backflip taking a punch, and a backflip giving one.
Modify qa-index.php:
if (isset($_GET['qa-rewrite'])) { // URLs rewritten by .htaccess
$qa_used_url_format=QA_URL_FORMAT_NEAT;
$requesturl=qa_gpc_to_string($_GET['qa-rewrite']);
$requestparts=explode('/', $requesturl);
if(preg_match('/^[-a-z]+\/[0-9]+$/',$requesturl)) {
$no = array_pop($requestparts);
array_unshift($requestparts,$no);
}
unset($_GET['qa-rewrite']);
$relativedepth=count($requestparts);
// Workaround for fact that Apache unescapes characters while rewriting, based on assumption that $_GET['qa-rewrite'] has
// right path depth, which is true do long as there are only escaped characters in the last part of the path
if (!empty($_SERVER['REQUEST_URI'])) {
$origpath=$_SERVER['REQUEST_URI'];
if(preg_match('/^\/[-a-z]+\/[0-9]+$/',$origpath)) {
$pa=explode('/', substr($origpath,1));
$no = array_pop($pa);
array_unshift($pa,$no);
$origpath = implode('/',$pa);
}
$_GET=array();
$questionpos=strpos($origpath, '?');
if (is_numeric($questionpos)) {
$params=explode('&', substr($origpath, $questionpos+1));
foreach ($params as $param)
if (preg_match('/^([^\=]*)(\=(.*))?$/', $param, $matches))
$_GET[urldecode($matches[1])]=qa_string_to_gpc(urldecode(@$matches[3]));
$origpath=substr($origpath, 0, $questionpos);
}
and qa-base.php:
case QA_URL_FORMAT_NEAT:
if(preg_match('/^[0-9]+\/[-a-z]+$/',$requestpath)) {
$up = explode('/',$requestpath);
$no = $up[0];
$title= $up[1];
$url.= $title.'/'.$no;
}
else $url.= $requestpath;
break;
This performs two backflips, one when receiving a url, and one when outputting it. I don't know if it will really work with answers, etc., but this is the easiest way I can think of, and it does work with simple question urls. It changes the output format to:
site.com/question-title/number
but only if the request is in the form number/question-title.