ZF-3807: URL assembly should include a trailing slash

Description

I cant find that in the RFC2616, but it's a well known issue. A request on http://my-server/my/ressource asks for the ressource file and not a directory. Assuming that the ressource doesn't exist but is in fact a directory, some servers will then redirect the client to the right URL : http://my-server/my/ressource/ (note the final slash)

Apache's mod_rewrite seems to correct that, but some other servers would not . As an exemple, try to ask for http://www.google.com/services , and watch the response from GWS. It responds a 303 code with a location to http://www.google.com/services/ (note the final slash).

This wastes ressources, both for the server, and all the Internet links as 1 HTTP request in fact needs 2...

Zend Framework's router does not generate final slashes on ressources, for exemple, try to use the url() view helper and you will notice that. This is mitigated by the fact that Apache's mod rewrite correct that, preventing a 30* response, but the problem is still present.

For more information I suggest : http://developer.yahoo.net/blog/archives/… http://httpd.apache.org/docs/2.0/mod/mod_dir.html

Comments

But what if you're using a Regex route, and your route can end in a file suffix? It seems to me that this should be either (a) optional, and/or (b) something defined in individual route assembly.

Can you document any web servers with the behavior you describe?

The Y! page you link to says this: {quote} One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. {quote} Please note the end of the phrase "from a URL that should otherwise have one." I'd argue that ZF URLs should not -- only URLs that actually represent directories would, as if the directory does not exist, mod_rewrite then rewrites the URL to ZF -- and no redirect is performed.

If other web servers do not behave this way, we can certainly add a flag -- but I don't want to go to the effort if it's an edge case that nobody is actually encountering.

I wrote Zend_View_Helper_Url plugin for redirect with 301 code to url with trailing slash. But I vote for additional option in FC. Thanks.

I agree with Matthew that ZF URLs should not generally end in a trailing slash, but it would be nice to have an option to include this incase you are redeveloping a site that has previously enforced trailing slashes and you want to preserve the URLs. I can't think of a good way to ensure that slashes are not added to URLs with file suffixes though.

I'm curious how other frameworks handle this. This is certainly a problem in Ruby on Rails. From some searching it seems Django has an APPEND_SLASH configuration option although I'm not sure exactly when this applies.