Uday Hiwarale Uo
Uday Hiwarale Uo

Reputation: 1

remove .php from file using htaccess

I want to tream .php from every url Like localhost/index.php ---> localhost/index But I also want localhost/index/ to work too....

Here is the current code I am using

#for hiding.php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)/?$ $1\.php [NC]
############################-------- END ---------########################

Can anybody suggest the changes?

Upvotes: 0

Views: 61

Answers (1)

Jon Lin
Jon Lin

Reputation: 143946

Try:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]

Upvotes: 1

Related Questions