Remove .php extension (explicitly written) for friendly URL

Posted by miquel on Stack Overflow See other posts from Stack Overflow or by miquel
Published on 2012-03-22T11:17:22Z Indexed on 2012/03/22 11:29 UTC
Read the original article Hit count: 214

htaccess to remove the .php extension of my site's files.

RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]

Now, if I go to my site

www.mysite.com/home

works fine, it redirects to home.php but the URL is still friendly.

But if I write this URL:

www.mysite.com/home.php

The home.php is served, and the URL is not friendly.

How can I avoid this behavior? I want that if the user writes www.mysite.com/home.php, the URL displayed in the URL bar be www.mysite.com/home

© Stack Overflow or respective owner

Related posts about php

Related posts about .htaccess