Allow omitting trailing slash when last segment is an optional parameter

Closes #935