I could be wrong but I understand it as more of a webserver issue than a
Django convention.
From: http://httpd.apache.org/docs/2.2/mod/mod_dir.html
"A "trailing slash" redirect is issued when the server receives a
request for a URL http://servername/foo/dirname where dirname is a
directory. Directories require a trailing slash, so mod_dir issues a
redirect to http://servername/foo/dirname/."
On Thu, Jan 28, 2010 at 8:54 AM, Brett Thomas <brettp...@gmail.com> wrote:
> Most of the URLConf examples I run across use a trailing slash on all URLs:
> www.example.com/profile/
>
> I'm not sure why, but I don't like this. I think it looks nicer without:
> www.example.com/profile
I believe that it is just a matter of personal preference: some people
like to always have a slash appended (or never appended) for
consistency. I prefer to append a slash when the page is some kind of
category, but leave it out when it is a "leaf node". (I noticed that
this is what the W3C website does.)
> Are there any performance or security reasons to use the trailing slash in
> Django? Seems like there could be some quirk with regular expressions that
> I'm not thinking of...
I do not know about performance, but I doubt there is a security
issue, otherwise it would not have made sense to make the APPEND_SLASH
setting behave the way it does, i.e., a slash is not appended if the
initial URL (without a trailing slash) can be found in the URLconf.
Regards,
Eugene Wee
If you don't have a trailing slash for something which is an internal
node, ie., can have child pages, and you use a relative URL rather
than absolute URL, then the relative URL will be resolved incorrectly
by the browser.
For example, if at '/some/path/' and returned HTML uses 'child.html',
then browser will resolve it as:
/some/path/child.html
if accessed as '/some/path' and returned HTML uses 'child,html', then
browser will resolve it as:
/some/child.html
which isn't want you want.
So, you use trailing slash if you want relative URLs in responses.
Either way, you should use one of the other and not allow both at the
same time. That is '/some/path/' and '/some/path' should not both
work. If you do allow both, then search engines will have multiple
entries for same resource. Also may stuff up caching systems or at
least reduce their efficiency as will keep multiple copies.
Graham
Ultimately, means you can also have a conflicting situation where you
decide you don't want to have a trailing `/` but you include URLs from
a 3p django application that do.