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
  • 56,865
  • 12
  • 98
  • 126

2 Answers2

2
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-_]+)/?$ $1.html [L]
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
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
  • 68,042
  • 28
  • 135
  • 158
  • 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