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 40 Comments

  1. Mr. Singh

    if i want *** don’t remove .php if anything in get in htaccess ** then what i will do


    While using this condition to .htaccess > .html website

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

    Unfortunately, menu button functionality is over riding.
    Means, before using this condition, the menu button get highlighted when visiting each pages.
    After apply this condition > MENU BUTTON – NOT to get HIGHLIGHTED on the menu bar HIGHLIGHTED MENU BUTTON on the menu bar < when visit every pages ?.

  3. Samuel

    Please how can i add a trailing slash after removing the .php extension? i will like it to appear like instead of

    Thank you

  4. Brenda

    It’s doesnt work for me 😔

  5. Muhammad Nur Ibrahim

    Thank You.
    It is working….

  6. VG

    Perfectly Working. Thanks.

  7. Mr Buchmas

    Mine wasn’t working until I did 2 things:

    1.) I deleted the .html from the navigation section for the other pages so that “blog.html” just read “blog”
    2.) I cleared cache data on my computer

  8. Md Zaheer Khan

    Amazaing artical share. I can remove .php my site

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

  10. agung

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

  11. Hayatu

    For me it doesnt work

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

  13. Marcos

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

  14. Brahim Djiddi Habre

    ouii oui c’est exactement

  15. aman

    you code not working

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

  17. Vikas Tiwari

    great, work for me

  18. Troy

    It works exactly as described. Thank you!

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

  20. Abdelkarim Ghaouri

    Doesn’t work for me :/

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

  22. Mo Weekly

    Thank you . Works well in Inmotion.

  23. Michael Tusi

    not working in Go daddy ?

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

  25. Harry

    Thank you..
    It’s works.

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