views:

67

answers:

3

I would like to get rid of all the file extensions on my site. Except when they are on the index i would like it to say nothing...

change this foo.com/index.html
to this foo.com/

and when the user goes to another page like foo.com/contact-us.html
it will be foo.com/contact-us

RewriteEngine On
RewriteRule ^ this is where i get confused :(

Thanks in advance!

+2  A: 

Try these rules:

RewriteRule ^index\.html$ / [L,R=301]
RewriteRule (.+)\.html$ /$1 [L,R=301]
Gumbo
Thanks a million!
PHPNooblet
what does [L,R=301] mean out of interest?
Matthew Lock
Im pretty sure it tells apache to not apply any more rules and redirects to a new url.
PHPNooblet
+1  A: 

I'd use a slightly different method:

RewriteCond %{REQUEST_FILENAME}\.html -f # if request.html exists and is a file
RewriteRule ^(.+)$ $1\.html [QSA] # then rewrite to that file.
TRiG
A: 

It doesn't have to be so complicated, apache has an option to accomplish what you want:

Just add this rule to your .htaccess and /contact-us/ will automatically be rewritten to contact-us.html:

Options MultiViews

That's it!

Robbert van den Bogerd