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

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

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 the 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. will become 
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. will become
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

Notice that many PHP scripts (like WordPress, Drupal, MediaWiki etc) need the .htaccess files to function properly. Don’t delete these files. Also, take care when editing them.

Check the video tutorial we made:

Remove html or php extensions

You can also edit .htaccess files on your web hosting account via an FTP client like FileZilla.

This Post Has 25 Comments

  1. Innocent Cyril

    Please how can I solved or hid .J’s, .css file extension

  2. Marcos

    This does not work well for me, if I put a trailing slash on my site…
    appears the extensions again.

  3. Brahim Djiddi Habre

    ouii oui c’est exactement

  4. aman

    you code not working

  5. EMMAN

    It’s working when you remove .html on the url it will still proceed to the page but when i click my navigation menu it’s still appearing as .html, can you please help me?

    1. PlotHost

      Maybe you have other Rewrite lines in the hataccess file? Make a backup and try with the above lines only to see if it’s working.

    2. Vishal

      May be you did not remove .html from your navigation menu, like index.html or about-us.html, remove html from navigation menu too.

  6. Vikas Tiwari

    great, work for me

  7. Joel Short

    How can I write the rule when I have a folder and page with the same name in the same folder? For example I have this folder: Within Folder1 I have another folder “Folder2” but also a webpage “Folder2.php” How can I get to show up as ?

    1. PlotHost

      DirectorySlash Off
      RewriteCond %{REQUEST_FILENAME}.html -f
      RewriteRule ^(.*)$ $1.html

      1. Joel Short

        Unfortunately that didn’t work. Most pages load fine without the filename extension, but those pages that have the same name as a folder do not load without the filename extension. Any other ideas?

  8. Troy

    It works exactly as described. Thank you!

  9. Abdelkarim Ghaouri

    Doesn’t work for me :/

  10. shihab kunnil

    then after we have to manually remove all .php/.html tag from all the links..otherwise this will still show like before..Am I right?

  11. Mo Weekly

    Thank you . Works well in Inmotion.

  12. Michael Tusi

    not working in Go daddy ?

  13. Equity Machineries Incorporate

    Hi, thank you very much. I am fixing the error redirection 301 to 200 in SEO and this code you gave help me to fix the last error in SEO Checker. It is not working offline but it work in our live website. I am not using apache that is why I am testing it online. Thank you so much.

  14. Harry

    Thank you..
    It’s works.

  15. Seamus Fitzpatrick

    Hi, very easy to read and understand, however, I am having trouble in that it doesnt work for me, and I dont know why

Leave a Reply