how to hide php extension in url using .htaccess

Posted January 4, 2017 108.2k views
PHPUbuntu 16.04

i want to be able to hide php extension in url so that if i got to login it will work the same way as if i was going to login.php

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
8 answers

Try my version:

# Run Php without filename extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

# Return 404 if original request is .php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]

You can use the following.

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

Basically this says if the File in the URL can’t be found on the server then in the backend load it again using .php. This will basically make the server take a /file request and because there is no /file on the server it will load /file.php instead. The user wont see the switch over but can still load both ways.

Very very thanks…
code working

Thanks for sharing..
Working fine.....

How to add 404 error page when extension restricted .php and .html both

If you looking for complete solution with explanation then i will recommended to Read this:
How to Hide PHP Extenstion Step By Step

You will get your answer 100%.

Hi the code is working fine ,the problem after login to my page it is re directing to next page ,please help it out, i launced my website in hostinger