Handle leading and trailing slashes in URI components