Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having some problems trying to

  1. Remove the .html extension from URLs
  2. Removing 'index.html' from an URL

1) To remove the extension I have tried using this in my htaccess file.

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

However when I click links in my HTML such as <a href="abcde.html"></a> it doesn't remove the .html from the URL and I am left with www.website.com/abcde.html

2) I tried using this to remove the index.html

RewriteCond %{THE_REQUEST} \/index\.(php|html)\ HTTP [NC]
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]

But when I load an index.html file on my server, my URL looks something like this


I am left with an extra / at the end.

Can anyone help me out?

share|improve this question

Building on the answer Anagio provided, let's cover all your requirements:

  • Transparently serve .html files on requests like /path/to/file if /path/to/file.html exists
  • Deny direct requests against /path/to/file.html
  • Serve /index.html on requests against /

Directory configuration:

Options +FollowSymLinks -MultiViews

DirectoryIndex index.html

RewriteEngine On
# Rewrite valid requests on .html files
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA]
# Return 404 on direct requests against .html files
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{QUERY_STRING} !rw=1 [NC]
RewriteRule ^ - [R=404]
share|improve this answer

This is from stackoverflow

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.