Website URL hiding/hiding file

3

1

Some websites, no matter what page you're on, always just show their domain name in the address bar and nothing else.

And many show the folders, e.g. https://superuser.com/questions/ask, but don't show the actual file, which would be like http://domain.tld/folder/file.extension.

How are both accomplished?

mk12

Posted 2009-10-17T23:16:35.250

Reputation: 2 432

Answers

9

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

Josh Hunt

Posted 2009-10-17T23:16:35.250

Reputation: 20 095

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.897

Anyway, +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.160

That only works on firefox for me, on safari its still search?. – mk12 – 2009-10-20T22:11:11.970

Mk12: See the question that Arjan linked to. Google is still testing this on certain people/markets – Josh Hunt – 2009-10-21T01:53:36.707

1

The file is a default as defined in the web servers config, or it's using URL re-writing (the folder path might not even exist).

AbsCoder

Posted 2009-10-17T23:16:35.250

Reputation:

Oops... forgot to address the domain name only question... This can be done by using a frameset, and only having the content's frame shown. – None – 2009-10-17T23:22:03.773

You can edit your answer instead of writing a comment. – Sasha Chedygov – 2009-10-18T19:39:17.447

IIRC, a person with a reputation of 1 can't edit his own posts. – CarlF – 2009-10-18T21:52:47.237

There, he can edit! Abs, would you mind editing your answer to include the comment? – Josh Hunt – 2009-10-21T01:55:21.710

0

What I was really looking for, is this: Just create a directory, have index.php/html inside the folder, and links to that directory won't show the file. Thanks for the other things too.

mk12

Posted 2009-10-17T23:16:35.250

Reputation: 2 432

1That's really more of a hack...url rewriting or content pointers are more commonly how it's accomplished – Chris Thompson – 2009-10-20T23:28:25.450