Use rtrim rather than ternary to remove trailing slash