Reputation: 3573
If I have a very simple http
directory:
default.html info.html contact.html etc...
Should default.html
link to the other files in the directory, I've always been able to simply use an anchor tag thus:
<a href="contact" target="_self">Contact me!</a>
Will this always work, assuming that there is only one file in the directory with a name matching this extension-less href
value?
Upvotes: 1
Views: 1036
Reputation: 113242
It depends on the server and how it is set-up.
Remember that there's no innate mapping between URIs and files on a webserver, the webserver is always following some sort of rule as to what file to send. The simplest takes the path part of the URI and does a direct mapping to a filepath local to the webserver, but it could be doing just about anything else. A common case is using the file extension to do con-neg, so if you have contact.html and contact.atom and so on in the same local directory corresponding to the path, it picks that closest to the Accept header from the user-agent.
Putting file extensions (whether of "static" files or handlers like .php, .aspx, etc.) in URIs is rather pointless since there is no such thing as a file on the web (there are files on the server, and the client can save the stream to a file, but on the web itself there are octet streams that may or may not correspond to a file). And less than ideal; presumably contact.html has something to do with contact details, while "contact" expresses this idea well, ".html" has nothing to do with contact details and doesn't belong there.
Hence the more sensible URI would not have ".html" in it, unless this was in some way expressing something useful (such as explicitly asking for a HTML version and bypassing content-negotiation, or if the page was actually about HTML).
On the other hand, just mapping directly to file names is a quick and easy way to do things, so while I certainly frown on such arbitrary cruft in URIs I won't jump through too many hoops not to use it, especially in secondary URIs used for stylesheets, images etc. rather than those which are expected to regularly appear in the address bar of a browser.
On the third hand, once you remove such cruft, adding more sophisticated handling later if required, becomes a much easier transition.
Upvotes: 3
Reputation: 9377
No it does not automatically appends .html
as he could not know which file extension to use. Let's say you have a contact.html
and a contact.php
. Which one should he use.
However you can do all this using rewrite rules (e.g. in a .htaccess file). Just search for some examples here on SO or in the web.
Upvotes: 1
Reputation: 6585
There is a content negotiation feature in Apache2 which does that, but personally, I do not like to rely on that.
If I need nice URLs, I'd better use mod_rewrite and implement completely custom url scheme which would be easy to modify & customize without limits.
http://httpd.apache.org/docs/2.0/content-negotiation.html
Upvotes: 2