Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come some site urls do not include a file extension?

I was browsing the internet and noticed, YouTube, for example, contains a URL like this to denote a video page: http://www.youtube.com/watch?v=gwS1tGLB0vc.

My site uses a URL like this for a topic page: http://www.example.com/page.php?topic_id=6f3246d0sdf42c2jb67abba60ce33d5cc.

The difference is, if you haven't already noticed that on youtube, there is no file extension for their watch page, so I am wondering, why do some sites not use file extensions and what use does it serve?

like image 264
Scarface Avatar asked Sep 02 '10 20:09

Scarface


People also ask

Is a file extension part of a URL?

A URL file is a shortcut that points to a specific Uniform Resource Locator. When you double-click a URL file, your computer accesses the URL the file contains. URL files most often contain https: web addresses and are used to access web pages. However, URL files can also contain mailto:, tel:, file:, or other URLs.

What are the uses of hiding file extension from Web pages?

The primary reason why the webmasters choose to hide the extensions from the URLs is to hide the underlying technology from hackers and other possible malicious attackers. For example, if a page ends with . html or .


2 Answers

File extensions are not used because of the idea that URIs (and therefore URLs) should be independent of implementation - if you want to access the CDC's information about food safety, you should be able to go to https://www.cdc.gov/foodsafety (for example). Whether the CDC's servers are using PHP or Python or Perl doesn't matter to the end-user, so they shouldn't see it. The end-user doesn't care how the page was generated, because all languages serving a webpage output the same HTML, CSS, and the like, and the user is just viewing the page in their web browser.

Most web frameworks build this functionality in by default, precisely for this reason, and it can be accomplished regardless with URL rewriting in most webservers. This ideal is codified in the W3C Style Guide, which is undoubtedly a big proponent in this idea being so widely accepted. It's outlined in their guide, "Cool URIs Don't Change", which should clear things up if you still don't quite understand the reasoning here. That document is the go-to statement on the issue, and the de facto standard for frameworks.

It is worth noting that usually files that end up being downloaded (and sometimes data files used in AJAX) will still have their file extensions intact - http://example.com/song.mp3 or http://example.com/whitepaper.pdf - because they are intended to be saved to the end-user's computer, where file extensions matter. The extensions are not included for pages that are simply displayed - which is most pages.

A postscript: The example page this answer originally linked to stopped existing at some point, because sometimes URIs do change, despite best practices. I've replaced it with the CDC's food safety page, which has existed in some form for at least 20 years now. Undoubtedly, numerous different technologies have served up that content over the years, while always doing so at the exact same URL.

like image 141
cincodenada Avatar answered Sep 17 '22 15:09

cincodenada


What you are seeing is an example of URL routing. Instead of pointing to a specific file (e.g. page.php), the server is using a routing table or configuration that directs the request to a handler that actually renders the html (or anything else depending on the mime type returned). If you notice, StackOverflow uses the same mechanism.

like image 20
Pete Amundson Avatar answered Sep 18 '22 15:09

Pete Amundson