Sorry for poor title.
I am now using
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Its works fine when using localhost/home
But my problem is when typing localhost/home.php it also works.I want to redirect when typing localhost/home.php to an error page that the requested page does not exist.
How could i do it with .htaccess or should i use php to redirect?
When you request the URL with the ‘.php’ extension, none of your .htaccess conditions are met, so the server (Apache) just serves the request normally. That’s why it works.
The easiest in my opinion is to add another rule before the previous one:
Add the
[R]option to theRedirectRuleif you want the browser to redirect (and I think you need to add a full path), eg: