Many times you will want to have user-friendly URLs on your site. Instead of https://wwwsinglewebsolution.com/index.html you will want to have https://www.singlewebsolution.com/index . The second URL looks much better. Also, from the SEO point of view is better to don’t use file extensions.

An .htaccess file is a simple ASCII file that you create with a text editor like Notepad, Sublime or any HTML, PHP file editor. It provides a way to make configuration changes on a per-directory basis.

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

The steps to remove file extensions are:

  • Login to your CPanel account.
  • Go to File Manager – in the FILES Section
  • In the File Manager go to the Settings button on the top right corner.
  • On the Preferences window that will appear check the Show Hidden Files (dot files) option. Click Save button to apply the settings.
  • Now navigate to the .htaccess file. If the file doesn’t exist you will need to create it.
  • 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.

#remove php file extension-e.g. https://www.singlewebsolution.com/page.php will become https://www.singlewebsolution.com/page

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

  • Now the Apache web server will remove .php extension from URLs.

To remove .html extension use:

#remove html file extension-e.g. https://www.singlewebsolution.com/page.html will become https://www.singlewebsolution.com/page

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

Leave a Reply

Your email address will not be published. Required fields are marked *