How can I load my page without .php extension

@dklynn

can I ask some help. I have this htacess rule

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9]+)/?$ edit.php?id=$1 [L]

It works fine if I point my browser like this

http://localhost/testfolder/1

I can echo the value 1

but I am having problem to load the page if I don’t have querystring set in url

example I have guess.php

how can I load the guess.php without .php extension ?

http://localhost/testfolder/guess

I tried to add this in my htaccess

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

it works http://localhost/testfolder/guess
but this will not work anymore http://localhost/testfolder/1

Thank you in advance

@dklynn I fixed it :slight_smile:

jemz,

Good!

I hope you changed the second RewriteRule set to something like:

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

Because you want to ensure that the requested filename does have the .php file extension, the dot character does not need to be escaped within a character range definition AND the No Case flag should NEVER be used against the %{REQUEST_URI} string (it is designed to be used against case INsensitive variables like {HTTP_HOST}).

Regards,

DK

1 Like

Thank you :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.