One simple option would be to use a regex to strip the end part. Something like
$url = preg_replace('#/([0-9]+)/[^/]+#', '/\1', $url);
Another way would be to just create the URL with the question ID. If you're on the question page it should be somewhere in the $qa_content variable.