0

I want to remove the file extension like .html from my websites with .htaccess. The final structure should be like so:

http://domain.com/file  --> http://domain.com/file.html
http://domain.com/file/ --> http://domain.com/file.html

With my existing code in .htaccess I'll get "Internal Server Error" on my Browser when there's a trailing slash at the end. What can I do? Thanks!

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Wladimir Palant
  • 55,537
  • 12
  • 95
  • 123

2 Answers2

2
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-_]+)/?$ $1.html [L]
Steve Robbins
  • 13,266
  • 10
  • 73
  • 122
0

I suggest you to change your RewriteCond :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule  ^(.*)(\.html){0}$ /$1.html [L] 

EDIT : rule edited, I forgot infinite loop.

zessx
  • 66,778
  • 28
  • 130
  • 153
  • Thanks for your answer. But I have still an error when there's a trailing slash at the end. It works fine when there's no slash. –  Jun 14 '12 at 16:26