Google App Engine optional slash redirect
I have a java app running on Google App Engine... I'd like to make the trailing slash optional for directories... so navigating to www.domain.com/test and www.domain.com/test/ would yield the same thing.
How do I achieve that?
I know about the app.yaml configuration file but 开发者_如何学JAVAI am running a Java app not python..
See this post. Works for me, though looks like a hack. I think it worth posting issue to google, as thee servlet specification requires adding trailing slashes when attempting to find a proper welcome-file.
The easiest way to do this would be to create a filter that intercepts requests and appends the forward slash if necessary. Generally it's better to send a redirect rather than serving the same content, so you don't end up with two canonical URLs for everything, and all your contents indexed twice.
What constitutes a 'directory' depends on your application, of course, and there's no hard and fast rule for figuring that out.
精彩评论