ZF-3807: URL assembly should include a trailing slash

Issue Type: Improvement Created: 2008-07-30T08:46:58.000+0000 Last Updated: 2012-05-29T17:40:31.000+0000 Status: Open Fix version(s): Reporter: julien PAULI (doctorrock83) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: - ZF-5367



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 , and watch the response from GWS. It responds a 303 code with a location to (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 :…


Posted by Matthew Weier O'Phinney (matthew) on 2008-11-05T08:25:08.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2009-10-16T06:47:50.000+0000

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.

Posted by Nikolay Goldschmidt (ccppprogrammer) on 2010-03-05T07:03:27.000+0000

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.

Posted by Tim Fountain (tfountain) on 2010-03-05T09:40:43.000+0000

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.