Akuta wrote:
I understand what you're saying about /tmp/ if it's a real directory, but if we're talking about a virtual directory setup as /virtual-directory, does the server still internally have to 301 to /virtual-directory/ to check for an "index" file, even though there's no difference client-side? (I hope that made sense, hah)
Since most of this thread has referred to static files, if by "virtual directory" you mean a location being handled purely in code as a representation of a resource on your site, then no, there's no requirement for a redirect, as you can return whatever data you want for whatever URI you receive. If you are using a framework for your code you may find differences in how you receive a request (or it is routed by the framework) with or without a trailing slash that you'll need to be aware of. But in the end it's up to you how you define your URI structure (and whether or not a trailing slash changes the interpretation of a resource).
Of course, when writing your application, you may find yourself implementing redirects even though they aren't technically required. For example, let's say you decide to return a resource under "/virtual-directory", do you now preclude using "/virtual-directory/", do you return something different or do you return the same thing?
If you're going to return the same thing, doing an internal redirect hides the fact that the two URIs are the same resource, which can affect search engine indexing, for example. It's actually better to do the external redirect to ensure that regardless of the initial request, the final resource being delivered has a canonical name. Of course, getting folks to use the canonical name in the first place then avoids the redirect. Any internal links within your site should always use the canonical versions.
-- David
PS: If at any point your code hands back control to the web server (say to more quickly satisfy a static file component), you'll be subject to that server's rules, which may be another reason to do some of your own redirects to align yourself with your local server behavior, at least for any URIs being satisfied directly by the server.