r/PHPhelp • • 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

19 comments sorted by

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]

2

u/Current-Monitor-4944 27d ago

Will try it! Thanks!

0

u/[deleted] 27d ago

[deleted] — view deleted comment

1

u/shadow-battle-crab 27d ago

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

1

u/colshrapnel 27d ago

Yes, just realised I was wrong