Url's without the ".html"

I have been asked an interesting question by a client:
Can you create a url that doesn’t end in “.html” ?

It seems they’ve made a printed mailer piece and left off the file extention, so if someone types in the address i.e. www.domainname.com/pagename (and leaves off the .html) they need that user to be able to get to the page www.domainname.com/pagename.html, possibly with some kind of redirect.

Does anyone know if this is possible?


There are probably more than 100 ways to do that. Here goes one of the easiest ones: create a “pagename/index.html” page. The web server will find the directory at the url and try to load the index page.

Other solutions will depend on your platform. For example, if you are running Apache with mod_redirect, you can add the folowing line to .htaccess:

Redirect 301 /pagename http://www.domainname.com/pagename.html

You don’t need a redirect. On most servers, the server will find the page just fine without the extension.

Why not use directories (folders) and put an index in each of them?

Then all you need is to point to www.site.com/folder1 or www.site.com/folder2 or www.site.com/folder2/subfolder1

This is also useful if you decide to change the technology used for instance if you ever wanted to change the .html to .php in order to use PHP in your pages you won’t have to update the links etc…

That would require a lot of folders. Simply linking to files without the extension will give the same benefits, without having a complicated folder structure. Furthermore, as I recall, Google does not consider example.com/folder and example.com/folder/ as the same page, leading to pagerank dillution.

Er, since when?


all of those use index.php, i removed the .php and nothing was found. They are all hosted on different servers as well, none that I have tried find it without the extension!

One with a .html extension:

http://archive.ncsa.uiuc.edu/primer - real page is primer.html - still 404.

That’s because the site owners put on their servers files called index.php or index.html!
Christian meant that the site owner puts a file called index without specifying the extension! :wink:
Chrisitian, I agree that the directories technique has some disadvantages but it has some advantages too especially if the web site ain’t huge :slight_smile: :wink:

Oh I see what you mean now. Sorry, misunderstanding! I thought he meant that you can just knock the extension off the request url and it would still work :confused:

It wouldn’t work for php files though, unless they were set up to run through the php engine. Normally only .php, .phtml etc files are parsed.

For Apache servers, it’s standard that you can just omit the extension, and it’ll work, regardless of whether the file has an extension or not (though files with the same name but different extensions can obviously create conflicts). Other servers have to have it specified in its settings.

Case of point - both of these URLs work just fine. I have not made any changes to the settings, and the files are saved with the .php extension:

Yes, for a small page, it wouldn’t be much of a concern (and might even be favourable, under some circumstances), but I wouldn’t want it for a page with hundreds of pages.

If it is an apache server then using mod rewrite would be easier because you can do it using the variables so everything is automatic.

The reason I didn’t suggest just removing the extension is that some servers won’t set the right content-type in the header, even though most will serve the html page just fine.

thank you one and all. Problem solved!
I just created a folder and named it for the page and then put an index page in it that was the page I wanted it to be and …presto!