0

I'm using the .htaccess below to remove the .html file extension but if someone types in

example.com/test

into the browser it redirects to

http://www.example.com/test.html

.

Why does the .html gets added and not removed?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 
Tom
  • 1
  • 1

1 Answers1

1

The line doing the substitution is

RewriteRule ^([^/]+)/$ $1.html 

which will unconditionally add .html to any request where the only slash after the hostname is the last character (e.g. http://example.com/test/, but not http://example.com/test1/test2/).

If you want to strip .html, try this:

RewriteRule (.*)\.html$ $1
Flup
  • 7,688
  • 1
  • 31
  • 43
  • Try it and it does not remove the .html. It's the same as before. `RewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule (.*)\.html$ $1` What else could I try? – Tom Apr 13 '13 at 13:23