Friendly URL’s Remove .html & .php

For those customers wanting to remove the .html and .php extensions from your website so that you have a much cleaner website you can add the code below to your .htaccess file. cPanel normally includes this rewrite rule by default however should your site still display the extensions you can use this code.

Additionally this rewrite rule also adds support for Google Bots so that your SEO is not affected which is a great addition to have.

# This tag ensures the rewrite module is loaded
<IfModule mod_rewrite.c>
 # enable the rewrite engine
 RewriteEngine On
 # Set your root directory
 RewriteBase /

# remove the .html extension
 RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
 RewriteRule (.*)\.html$ $1 [R=301]

# remove index and reference the directory
 RewriteRule (.*)/index$ $1/ [R=301]

# remove trailing slash if not a directory
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_URI} /$
 RewriteRule (.*)/ $1 [R=301]

# forward request to html file, **but don't redirect (bot friendly)**
 RewriteCond %{REQUEST_FILENAME}.html -f
 RewriteCond %{REQUEST_URI} !/$
 RewriteRule (.*) $1\.html [L]

Also you can test the rewrite rule using this curl command via a terminal:-


You should receive a response similar to the one below if you have setup the rewrite rule correctly.

HTTP/1.1 301 Moved Permanently Date: Sat, 29 Jun 2013 19:45:15 GMT Server: Apache Location: Content-Type: text/html; charset=iso-8859-1