-23

Why does Stack Overflow hide the file extensions in their URLs? For example this URL has questions instead of questions.php or some other extension:

https://meta.stackoverflow.com/questions/307712/why-hide-the-fileextensions

What does that accomplish? What does hiding the file extensions in general accomplish? Is it just for styling purposes? Or is there more to it?

11
  • meta.stackoverflow.com/questions/307712/… @AlexeiLevenkov
    – frosty
    Oct 9, 2015 at 2:00
  • @AlexeiLevenkov you see it has "questions" instead of "questions.php" or some other extensions?
    – frosty
    Oct 9, 2015 at 2:00
  • 3
    that link to a post... It is not a file of any kind. Clarifying what you expect may make it more on-topic... Additionally it would be nice to explain why adding something like ".php" would be useful - I don't see any benefit of doing so, but you may. Otherwise you can safely answer to yourself - "no idea why they would do so... so they did not". Oct 9, 2015 at 2:01
  • @AlexeiLevenkov You know when you have a main page, it's always call index? But it has an extension, yes? There are many file extensions, but let us just use the php extension for explanation purposes. So then it would be named index.php. But you have more than 1 page on your website, yes? So you must make more files to hold them. So, for example, you make another file called login.php, and to get to that page you would either have to type something like "www.website.com/login.php", or click a link to access it.
    – frosty
    Oct 9, 2015 at 2:05
  • @AlexeiLevenkov At least that's how I understand it. As far as I can tell, if you don't include the extensions, it brings you to an invalid page, an non-existing page. That's how it works on my server at least.
    – frosty
    Oct 9, 2015 at 2:07
  • @AlexeiLevenkov For example, check out this website. chatwithibot.com/contactUs.php If you include the php extension, it brings you to a valid page, but if you takes it off, it takes you to an invalid page.
    – frosty
    Oct 9, 2015 at 2:09
  • 4
    I suspect you may have question for SO (how to do that) but probably don't yet have good META question as there is no reason why one would add extensions to url (except "I don't know how to do otherwise", which is not a good reason). Oct 9, 2015 at 2:09
  • @AlexeiLevenkov I disagree. There must be a good reason for doing something if that something isn't doing nothing. There must be a better reason to hide the extensions, other than "because there is no reason not to". You don't just do something because there is no reason NOT to do it.
    – frosty
    Oct 9, 2015 at 2:12
  • 4
    webmasters.stackexchange.com would be a good place to ask that question like Why are extensions often hidden on URLs Oct 9, 2015 at 2:14
  • 12
    When you're a high-level webwizard you can cast the 'greater obscure URLs' spell. Oct 9, 2015 at 2:16
  • @AlexeiLevenkov Thanks for the recommendation. I'll keep that in mind.
    – frosty
    Oct 9, 2015 at 2:16

1 Answer 1

30

The actual extensions are not able to be expressed in any normal character set; Unicode does not contain a range for the language of the Great Old Ones. Even if it were possible to represent these extensions accurately, attempting to read them has been known to drive men mad. Respected developer Abdul Alhazred, who wrote at length on the languages used to develop these sites, referenced these extensions only in shrouded terms, and warned against further investigations - the tales of those who've failed to heed these warnings are grim indeed.

(There is no 1-1 mapping between most of the URLs on Stack Overflow and the files which contain the code used to generate them; the URLs are designed to convey sufficient information to both the humans that read them and the machines that parse them, without needing any further adornment. As good an explanation as any can be found on MSDN)

17
  • 2
    Long story short, it's just for styling purposes?
    – frosty
    Oct 9, 2015 at 2:18
  • 7
    Yes didn't you read URL Fashion Magazine 2015? Extensions are soooo 2008
    – user703016
    Oct 9, 2015 at 2:18
  • @GregorMcGregor Well, I never really had a good reason to hide them.
    – frosty
    Oct 9, 2015 at 2:20
  • 12
    @frosty There's nothing to "hide" since there was nothing there to begin with. Oct 9, 2015 at 2:24
  • @CatPlusPlus I think not. You need to use extensions if you don't hide them. Files just don't start out with no extensions. Every files starts out with extensions, and it seems like there is a way to hide them in links if you know how. If you don't hide them, and attempt to access a page without the file extension, it'll bring you to an invalid page.
    – frosty
    Oct 9, 2015 at 2:26
  • 9
    @frosty Extensions are not magic and no files don't need them. HTTP server can dispatch the request to wherever it wants, including a function in a running application (if you know these things and you complain that's oversimplified I'm going to eat you). No files involved except for server executables. Oct 9, 2015 at 2:30
  • 7
    As I said, there's no one file here @frosty. Merely rendering a question involves multiple files - and multiple extensions - for controllers, views, partial views, eldritch horrors, models... The URL is defined in terms of a route that... you know what, just read the link at the end of this answer, or, if you prefer, the same link without an extension.
    – Shog9
    Oct 9, 2015 at 2:30
  • @CatPlusPlus I literally have no idea what you just said.
    – frosty
    Oct 9, 2015 at 2:33
  • @CatPlusPlus You know what, I'll just assume this is for styling purposes, and move on now.
    – frosty
    Oct 9, 2015 at 2:34
  • 12
    @frosty Here's an exercise for you: save this as butts (note no extension) and run python butts (you'll need Python 3.5) and then visit http://localhost:8000/whatever and http://localhost:8000/whatever/else. Oct 9, 2015 at 2:41
  • I understand that you need to change some codes in htaccess for that to work, depending on whether htaccess already has the codes or not, for not needing to include extensions. By default, my web server forces us to include the extensions when we make new files. If we don't include them, a message pops up, saying invalid filename. That's why I thought we always need to include them.
    – frosty
    Oct 9, 2015 at 2:46
  • @CatPlusPlus Forgot to tag you.
    – frosty
    Oct 9, 2015 at 2:46
  • @frosty There's no htaccess. The code I posted is literally a web server. There is no Apache also who uses Apache these days anyway. Oct 9, 2015 at 2:49
  • 8
    @frosty a (simplified) example of what goes on behind the scenes: client sends HTTP GET request to server -> server breaks the URL "path" into a set of parameters -> params are passed to a routing method -> certain code is executed accordingly (might fetch data from a DB, check auth/session status, etc) -> server responds to client with whatever resources and a status code. Most websites aren't just static file hosts; there's a lot going on behind the scenes. Hopefully that wasn't too confusing.
    – nick
    Oct 9, 2015 at 2:52
  • 7
    @frosty No problem. Point is, how a server handles an HTTP request from a client is totally arbitrary. Most modern sites avoid 1:1 mapping to static files. It just doesn't make sense when you think about it. Take this website for example- data is constantly changing and is updated in real time on the client (upvotes, comments, rep, pings, etc). But when you reload this page, the client does not reload all that data through separate channels again. The server will pre-render the whole document for you with the current data, then cache it for future requests.
    – nick
    Oct 9, 2015 at 3:10

Not the answer you're looking for? Browse other questions tagged .