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

Many times you will want to have user-friendly URLs on your site. Instead of https://www.example.com/index.html you will want to have https://www.example.com/index . 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. 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]

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

  1. Genxtranslators

    It helped me a lot … Thanx

  2. Lisaiceland

    not working

  3. Somyatrans - Localization Service

    I have used this answer and now i have successfully remove extension from my website.
    Thanks to you.

  4. Mr. Singh

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

  5. DEVELOPER

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

  6. Samuel

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

    Thank you

  7. Brenda

    It’s doesnt work for me 😔

  8. Muhammad Nur Ibrahim

    Thank You.
    It is working….

  9. VG

    Perfectly Working. Thanks.

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

  11. Md Zaheer Khan

    Amazaing artical share. I can remove .php my site

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

  13. agung

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

  14. Hayatu

    For me it doesnt work

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

  16. Marcos

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

  17. Brahim Djiddi Habre

    ouii oui c’est exactement

  18. aman

    you code not working

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

  20. Vikas Tiwari

    great, work for me

  21. Troy

    It works exactly as described. Thank you!

  22. 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: mysite.com/Folder1 Within Folder1 I have another folder “Folder2” but also a webpage “Folder2.php” How can I get mysite.com/Folder1/Folder2.php to show up as mysite.com/Folder1/Folder2 ?

    1. PlotHost

      Try
      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 example.com/Folder1/Folder2 Put the rules in /Folder1/.htaccess

  23. Abdelkarim Ghaouri

    Doesn’t work for me :/

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

  25. Mo Weekly

    Thank you . Works well in Inmotion.

  26. Michael Tusi

    not working in Go daddy ?

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

  28. Harry

    Thank you..
    It’s works.

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