Removing File Extensions using .htaccess

Lately, there seems to be a trend where designers want to cloak their file extensions from their visitors. For example, they want the URL domain.com/index.html to display as domain.com/index for whatever reason. Some like the way it looks, others believe it helps with SEO, and others believe it is better for security. I am unsure the last two hold any bit of truth, however. This is a feature you can implement via your htaccess file. This article will guide you through doing so via your cPanel.

How to Remove File Extensions from URLs via htaccess

  1. Log into your cPanel.
  2. Find the Files category and click on the File Manager icon.

    Click on File Manager in cPanel
  3. In the top right hand corner, click on Settings. For the primary domain, click on the Web Root radio button. For addon domains, click on the dropdown and find your desired addon domain name. Be sure the checkbox next to Show Hidden Files is checked. Click the Save button to return to the main File Manager screen.

    Show hidden files in settings
  4. You should now be in the root folder of the domain you chose. Look for the .htaccess file and right click on it. This brings up a menu. Find and click on the Edit option. If you get a popup box, simply find and click the Edit button in the lower right corner to continue to the editor.

    Click on edit
  5. You are now in the text editor. As most sites are coded with either html or php, we have include the code for both below.



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

     
    Apache
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html
  6. Be sure to hit the Save Changes button in the upper right corner to save your new htaccess configuration. Your site should now display the address without the file extension.
Share this Article