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:

How to remove extension from URL

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

This Post Has 33 Comments

  1. Md Zaheer Khan

    Amazaing artical share. I can remove .php my site

  2. thennarasu

    doesn’t work at all for me?

    1. Hassnain

      Use this for .php file
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^([^\.]+)$ $1.php [NC,L]
      For .html file last line replace with
      RewriteRule ^([^\.]+)$ $1.html [NC,L]

  3. agung

    It’s work but if the function of header() (redirect) is not work. Help me to fix it.

  4. Hayatu

    For me it doesnt work

  5. Innocent Cyril

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

    1. Intreped

      why do you have to hide .css and .js

    2. LSTV

      You do not have to hide .js or .css, you do not visit them.

  6. Marcos

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

  7. Brahim Djiddi Habre

    ouii oui c’est exactement

  8. aman

    you code not working

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

  10. Vikas Tiwari

    great, work for me

  11. Troy

    It works exactly as described. Thank you!

  12. 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?

      2. PlotHost

        I’ve tested it before posting here. It worked for me. Maybe you have some other rules. Clear the web browser cache. Access it without the / at the end – like you said Put the rules in /Folder1/.htaccess

  13. Abdelkarim Ghaouri

    Doesn’t work for me :/

  14. 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?

  15. Mo Weekly

    Thank you . Works well in Inmotion.

  16. Michael Tusi

    not working in Go daddy ?

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

  18. Harry

    Thank you..
    It’s works.

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