How do I remove extensions like .php, .html from file names?

  • September 13, 2017
  • 0 Comments

Lately, there seems to be a trend where website owners 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. This is a feature you can implement via your .htaccess file. This article will guide you through doing so via your cPanel.

Read this article if you are unable to find your .htaccess file. To remove file extensions:

1. Specify which file extensions your website is coded in. As most sites are coded with either htm or php, we will use these examples. Paste the following code into your .htaccess file:

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

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

2. 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.

How helpful was this article to you?