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

  • 0

 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.
  7. 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://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]
    
  8. Now the Apache web server will remove .php extension from URLs.

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]

Was this answer helpful?

« Back