Extension-less URLs

Every now and then, I notice this particular thing: URLs without extensions (or a slash, as to not to reference to a directory) at the end (like domain.com/blah instead of domain.com/blah.html). Every time I do notice, I wonder how it’s done, because my past experiences with web hosts would not allow extension-less URLs.

I’ve concluded at one point or another that it’s index files in folders. I thought it was such an inefficient use of a file system, so I kind of dismissed it. But yesterday night, I was trying to find a folder in my current web server from a place I couldn’t access the FTP. When the file does not exist, it defaults to the index file (and if not in the current folder, it goes to the parent folder’s index file). This always happened, but I never thought of the reason why it does this.

When I got home that night, I noticed the extension-less URLs again, but instead of concluding it was a folders thing, I researched about it (aka Googling). I had this idea that the extension-less URLs were the results of extension-less files that is being interpreted as an HTML or PHP file, so I searched relating to that idea. After a few keywords switching, I found exactly what I needed. It wasn’t the idea I had in mind (which is actually not at all valid), but it’s what I needed for extension-less URLs to work, and understand why this works.

The key to understanding how and why this works is how the protocol HTTP works. HTTP requests only sends the URL text to the server, and the server interprets the request however the hell it wants, and send back whatever the hell it wants. HTTP never looks at the file extension in the URL text; it just simply sends the thing.

It’s the web server that’s responsible with the interpretation of the HTTP request. It can be configured to return what we want according to the request. Specifically, we can edit the server config or .htaccess file to return whatever we want. So, we won’t need an extension-less file to do our bidding.

There are a couple of ways to do this, but the one that requires the least work (for Apache servers) is this option called the MultiViews. It enables a kind of search-and-return thing, where if the requested thing doesn’t exist (i.e. an extension-less file like “blah”), it will search for a file or folder that DOES have that name. I’m not entirely sure about how the server prioritize the file types by default (like if blah.html and blah.php and a folder called blah were all in the same folder, which one would be returned), but if there’s no other file or folder with that name, it will return the file or folder with that name.

With that part figured out, I connected the extension-less URLs with the weird redirection referencing of my current web server. I tested it out with one URL, and it works! So I changed a few things to make the extension-less URLs the main thing to navigate around, and yeah, it works beautifully.

So, there we go. My journey into understanding how extension-less URLs are achieved.

tl;dr, I learned how and why extension-less URLs work and applied it to my website.

  1. jayther reblogged this from rawringpenguin and added:
    took me 6 years.
  2. rawringpenguin posted this

Name: J'Brian
Age: 20

This blog is my productions blog. I will mainly post whatever stuff I make that will emphasize what I specialize in.

What the blog will probably contain:
- Ideas for program, design, or product
- Drawings of ideas/concept
- Music I made (drafts and final)
- Links to websites/programs/designs/products I made or was a part of
- Work-in-progress stuff
- Unrelated but interesting (hobby-ish stuff)

Skills:
- Website design (HTML, CSS, Javascript)
- Graphic design (Photoshop and Illustrator)
- Programming (C/C++, Java, BASIC, Flash ActionScript 2/3, LUA)
- Adept at learning new programming languages

Website: http://www.rawringdesigns.net/
YouTube: http://youtube.com/jayther


Theme: Rawring Penguin by jayther/rawringpenguin