handle directories with and without trailing slashes