Get Rid of File Extensions

This is a simple way of doing it by replacing files with folders. It does not make use of .htaccess or mod_rewrite.

This was one of my early questions doing web work and it does get asked often in forums. The file extension seemed like a bit of litter to me, just one more thing a person has to remember if s/he is ever going to type their way to your page.

I was trying to find this out for awhile. It was surprising how hard it was to get the details laid out clearly and simply from on line information, so now that I do have it, I might as well pass it around.

There is more than one way to do it, but the simplest way goes like this.

First go to the public folder. For any file that you want an extensionless url, create a folder with the same file name, but without the extension. Eg if the page is yoursite.com/bike.html create a folder named bike.

Copy the file bike.html and put it in the folder “bike,” but rename it there to index.html.

If you use an external style sheet there is an extra step with choices. The simplest is to copy the sheet and include it in your folder, with its original name. The most bandwidth efficient way is to make one small change to your new index page. Toward the bottom of the head section you will have a line like <link rel=”stylesheet” type=”text/css” href=”style1.css” media=”screen” />.

In this example your style sheet is called style1.css. This is the link to your css sheet and you can modify the path now to “../style1.css”. The ../ means “up a level.” If your page links to images you will have to correct their path also. Just adding the same 2 dots and a slash will do it for them too.

Using an absolute URL like http://yoursite .com/style1.css is another way of doing it. Especially with folders, using absolute URLs for internal navigation will save some problems.

If you want your internal links to link to the extensionless urls, go through the internal navigation and take off the .htmls. It is just a bit too easy to take off one character too many, or one not enough doing this. Make sure you have had your coffee.

At this point you will have a set of files that will work with the .html URLs, and a set of folders that will work without the .html. If you don’t need the site to work both ways you can delete one set, but unless you have large files, it doesn’t hurt to leave them in place, at least for awhile until you are sure everything is working well. If you do have sites linking to you with the .html links already, you can just leave them until the traffic to them tapers off.

If you have a second set of files under the www folder you might want to repeat the process for that url.

Of course this isn’t the way CNN does it.

There might be a small disadvantage or two doing this. If you use an html editor that opens pages in tabs, all your tabs will say index.html. That might be enough to inspire a quick trip to a liquor store. But once a site starts growing, folders are needed to keep it organized. If you have a page about bike repairs for example, you could put it in the same folder. The URL would be yoursite.com/bike/bike-repairs. You might even have a small SEO benefit from having an extra, closely related keyword.

Another way is to set up subdomains. You will have a URL like bike.yoursite.com. This results in the same folder system as the last method. You just get to it by a slightly different URL. Again you will have to include an external style sheet in each folder that uses one, or modify the link to the style sheet.

To set up a subdomain with the DirectAdmin control panel, if you have more than one domain click on the domain you want to work with in the list on the left. Then click on “subdomain management.” After that it is as simple as typing in the name you want for the folder. Then you can insert your index.html page into that folder. FTP works fine but even copy and paste will get the job done.

Leave a Reply

Your email address will not be published. Required fields are marked *