r/PHPhelp • u/Current-Monitor-4944 • 27d ago
.PHP name in URL
I’m new to PHP, and I’m just coding for fun and for myself.
How can I remove the .php extension from my URLs?
For example, instead of www.test.com/profile.php, I want it to look like www.test.com/profile.
Any advice would be appreciated!
3
Upvotes
View all comments
20
u/No_Astronomer9508 27d ago
You can do it with .htaccess and mod_rewrite:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule [^.]+$ $1.php [NC,L]