r/PHPhelp • • Oct 21 '26

.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

19 comments sorted by

View all comments

20

u/No_Astronomer9508 Oct 21 '26

You can do it with .htaccess and mod_rewrite:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule [^.]+$ $1.php [NC,L]

2

u/Current-Monitor-4944 Oct 21 '26

Will try it! Thanks!

0

u/[deleted] Oct 21 '26

[deleted] — view deleted comment

1

u/shadow-battle-crab Oct 21 '26

No, this is the way this kind of thing is done...

1

u/colshrapnel Oct 21 '26

Yes, just realised I was wrong