Mobile app version of vmapp.org
Login or Join
Shanna517

: Clean urls and differences in hosts 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

@Shanna517

Posted in: #CleanUrls #ModRewrite #UrlRewriting

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shanna517

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

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:

httpd.apache.org/docs/current/mod/core.html#options http://httpd.apache.org/docs/current/content-negotiation.html#negotiation (scroll a bit until you see Multiviews header)




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 ^(.+)$ .html [L,QSA]


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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme