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:
You can also edit .htaccess files on your web hosting account via an FTP client like FileZilla.
It helped me a lot … Thanx
not working
I have used this answer and now i have successfully remove extension from my website.
Thanks to you.
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 ?.
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
It’s doesnt work for me 😔
Thank You.
It is working….
Perfectly Working. Thanks.
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
Amazaing artical share. I can remove .php my site
doesn’t work at all for me?
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]
It’s work but if the function of header() (redirect) is not work. Help me to fix it.
For me it doesnt work
Please how can I solved or hid .J’s, .css file extension
why do you have to hide .css and .js
You do not have to hide .js or .css, you do not visit them.
This does not work well for me, if I put a trailing slash on my site…
appears the extensions again.
ouii oui c’est exactement
you code not working
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?
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.
May be you did not remove .html from your navigation menu, like index.html or about-us.html, remove html from navigation menu too.
great, work for me
It works exactly as described. Thank you!
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 ?
Try
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
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?
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
Doesn’t work for me :/
Gr8 . that solved my issue
doesn’t work at all for me?
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?
Thank you . Works well in Inmotion.
not working in Go daddy ?
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.
Thank you..
It’s works.
Hi,
I trying with the below URL to hide .php extension with the same.
Please help me with the same.
http://localhost/mysite/api/users.php/users/abcdf/12345
Hi, very easy to read and understand, however, I am having trouble in that it doesnt work for me, and I dont know why
I used it for my website. Thanks
Thanks a lot for this.
Happy to help 🙂 Thank you.