Fixing routing bug in Joomla 3.1

Fixing the bugs described here: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=31107