How to remove .php, .html extensions with .htaccess

You will learn How to remove .php, .html extensions with .htaccess.

Generally you will need to have user-friendly URLs to your site. As opposed to https://www.Instance.Com/index.Html you will need to have https://www.Instance.Com/ The second URL seems a good deal better. Also, from the search engine optimization factor of view is better to don’t use report extensions.

What is an .htaccess file

An .htaccess file is a simple ASCII file that you create with a text editor like Notepad or TextEdit. The file lets the server know what configuration changes to make on a per-directory basis.

Please note that .htaccess is the full name of the file. It isn’t file.htaccess, it’s simply .htaccess.

.htaccess files affect the directory in which they are placed in and all children (sub-directories). For example if there is one .htaccess file located in your root directory of yoursite.com, it would affect yoursite.com/content/yoursite.com/content/images/, and so on…

It is important to remember that this can be bypassed. If you don’t want certain .htaccess commands to affect a specific directory, place a new .htaccess file within the directory you don’t want to be affected with the changes, and remove the specific command(s) from the new file.

With an .htaccess file you can:

  • Redirect the user to different page
  • Password protect a specific directory
  • Block users by IP
  • Preventing hot-linking of your images
  • Rewrite URLs
  • Specify your own Error Documents

The steps to remove file extensions are:

  1. Login to your cPanel account.
  2. Go to File Manager – in the FILES Section
  3. In the File Manager go to the Settings button on the top right corner.
  4. On the Preferences window that will appear check the Show Hidden Files (dotfiles) option. Click Save button to apply the settings.
  5. Now navigate to the .htaccess file. If the file doesn’t exist you will need to create it.
  6. Click the Edit button from the File Manager top menu.

Add the below lines to the .htaccess file. Click the Save Changes button and then the Close button.

To remove .php extension with .htacess

#remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

Now the Apache web server will remove .php

To remove .html extension use:
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
Now its all set! you can now Remove files extention with .htacess