I am using cPanel to build a website and I am not sure how to take the .html or .php file extension off my webpages. Usually I will use a python framework and I do the routing manually but I am not sure how to do it with cPanel. I saw something about using .htaccess but I am not sure what I would need to put in there.

1 Answer 1


This is how you'd remove the .html extension using a .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp

To add a trailing slash at the end of the URL (for example: http://www.example.com/about-us/ to go to http://www.example.com/about-us.html)

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

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
  • @anaglo does this have any effect on seo ?
    – sam
    Nov 17, 2012 at 23:17
  • 2
    @sam yes if your website has already been indexed with file extensions changing your URL structure will most likely affect your rankings. You'll have to create 301 redirects from the old pages to the new pages. If it's a new website it does not matter which you use
    – Anagio
    Nov 17, 2012 at 23:34
  • great thanks! any idea how to set my default page? I have the line DirectoryIndex index.html site-down.php in there and my page is called index.html but it is showing a different one.
    – clifgray
    Nov 18, 2012 at 1:16
  • What page is it showing?
    – Anagio
    Nov 18, 2012 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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