This is because of a bit of a misconception with what a URL actually is, probably helped by the days of static .HTML files and PHP scripts.
Traditionally, everything past the TLD is a pointer to a specific file. Say a blog post is located at example.com/blog/2009/oct/18/what-have-we-come-to
. Without the use of fancy techniques, it would mean that there is a folder called blog, and in that is a 2009
folder, and in that a folder for every month, and in those folders ANOTHER folder for every day of the month. Clearly, this gets very complicated very quickly.
That is why web servers (such as Apache) and programming languages (such as PHP) invented URL rewriting. What that does is converts the said URL into something a bit more manageable, such as example.com/blog/articles.php?id=423
. Here, a the articles.php
script will use the provided post ID to look up the applicable post, then it will display the post, but the user would still see the URL as example.com/blog/2009/oct/18/what-have-we-come-to
.
Another approach just scraps all this entirely. Everything past the TLD (in this case, /questions/56772/website-url-hiding-hiding-file
) is merely a pointer to content, not necessarily a file. Some websites, such as Super User, a built using a MVC (Model-View-Controller) approach. Usually, this involves a list of URLs for a website, and maps them to the applicable functions and code in order to display that page. For example, Super User might look like this1:
'superuser.com/' > displayFrontPage()
'superuser.com/questions/' > displayQuestionsList(sorted=default)
'superuser.com/questions/<QuestionID>/<QuestionID>' > displayQuestion(question= QuestionID)
This would most commonly be placed in a file by itself. I a common layout might be:
superuser/
controller.aspx (which contains the list of URLs and points to a view in views.aspx)
views.aspx (which contains all the code for the superuser, such as displayFrontPage() and displayQuestion(question= QuestionID))
models.aspx (which contains information about the table in the database.)
1Please keep in mind that I have no idea how the controller works for ASP MVC (I am more of a Django guy), so this probably isnt that accurate. It is just an example
Where would that code be placed? – mk12 – 2009-10-17T23:48:40.023
It would depend on the server configuration or the actually framework being used. I will update my question appropriately. – Josh Hunt – 2009-10-17T23:53:11.167
What about google, for instance google.com/search?client=safari&rls=en&q=superuser&ie=UTF-8&oe=UTF-8, notice search has no file extension… – mk12 – 2009-10-18T19:38:14.797
@Mk12: The programmer can choose to use any URL he/she wants. I could write a web application that puts
.php
at the end of every URL, when in fact there are no PHP files anywhere on the server. So Google decided to simply use "search" without any extension. They could have done something like this, if they had wanted (and it wouldn't have actually changed anything):google.com/search/client=safari/q=superuser/
– Sasha Chedygov – 2009-10-18T19:40:47.897Anyway, +1, good description. – Sasha Chedygov – 2009-10-18T19:41:58.893
+1, but note that in the folder example there would be an index.html/php/whatever (unless the server is configured to use a different default filename, then it'd have that) – Phoshi – 2009-10-18T20:20:01.110
In fact, @Mk12 and @musicfreak, Google is changing that URL to http://www.google.com/#client=safari&q=superuser ;-) See http://stackoverflow.com/questions/1122523/google-using-instead-of-search-in-url-why
– Arjan – 2009-10-18T20:56:04.160That only works on firefox for me, on safari its still
search?
. – mk12 – 2009-10-20T22:11:11.970Mk12: See the question that Arjan linked to. Google is still testing this on certain people/markets – Josh Hunt – 2009-10-21T01:53:36.707