Fixes #5703, prevent infinite loop on trailing slash.

http://projects.theforeman.org/issues/5703