Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am developing a relatively static website, where I want to be able to access each page without typing .html (or .htm or .xhtml ...) at the end (/about not /about.html).

I am developing using the Apache 2.2 server (in OSX). Links like the above work just fine. No monkeying around with mod_rewrite, they just work.

However, on my actual web host (fatcow.com) this does not work (a link to /about just raises a 404 error). I've called them and they don't seem to know what is going on... or particularly think it is their problem. They are using Apache 2.0.

What is going on here and what is the best method for getting around it? I'd prefer a solution that didn't involve adding a mod_rewrite entry for each of my pages, but if that is needed how would I do that?

For reference, if I do go with a mod_rewrite solution it would look like:

RewriteEngine On
RewriteBase /
RewriteRule ^about$ /about.html
#and so on, for each page
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You need to add the following line into your .htaccess file(s):

Options +MultiViews

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

See these links for details:


UPDATE:

If you need to go with mod_rewrite then use this rule -- it will attempt to rewrite all extensionless URLs to the same but with .html. There will be no need of specifying individual rules for each of such URLs:

RewriteEngine On
RewriteBase /

# add .html file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]

P.S. You may need to add a lash / before $1 -- depends on your Apache config.

share|improve this answer
    
Tried it but failed. Raises a HTTP Error 500 Internal server error. –  Adam Greenhall Jul 8 '11 at 17:31
    
@Adam By adding this line you have 500 error? Hmm .. what Apache error log says about this? It may be that it is forbidden to overwrite these settings on your hosting .. or you did it wrong somehow (no idea). –  LazyOne Jul 8 '11 at 17:41
    
@Adam If, in the end, you will have to use mod_rewrite, use this rule (see updated answer) –  LazyOne Jul 8 '11 at 17:52
    
I'm not sure why MultiViews doesn't work. I suspect fatcow doesn't allow this (and has tech support grunts that don't know that). The rewrite rule works great - thanks. –  Adam Greenhall Jul 11 '11 at 17:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.