[#33598] SEF wrong path - Revival of issue 1272 - proposed the fix

Here is a revival of an issue reported in Github
#1272

See also bug tracker #33598
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33598&start=0

This is a copy of the implementation proposed in Pull Request #1869
https://github.com/joomla/joomla-platform/pull/1869

This affect both J2.5 and 3.2