0

The pages load without any trouble when there is the .php extension with the URL but it gives error Not Found while trying to access the same page without .php extension.

.htaccess

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

With extension


Without extension

Before posting this I have searched a lot.

  1. mod_rewrite for removing .php extension is producing 404 error
  2. Using .htaccess for remove .php extension but folder access returns 404
  3. getting 404 error when removing file extension worked on wamp but not working on lamp
  4. Removing URL .php extension gives 404 error

Thanks for your help.

Sumithran
  • 6,217
  • 4
  • 40
  • 54

2 Answers2

0

Just place the following into your .htaccess file (and make sure that mod_rewrite is enabled):

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
Sunny Kalariya
  • 336
  • 2
  • 9
-1

try to check your vhost the AllowOverride should be enabled.

Something like this :

<Directory /your/path/here>
    AllowOverride All
</Directory>

https://httpd.apache.org/docs/2.4/en/mod/core.html#allowoverride

  • This is not a bad suggestion, but it is still a stab in the dark since we don't know if the OP already have this. Just a heads up: Suggestions like this (where we don't know enough) and questions should be written as comments, not as answers. – M. Eriksson Sep 18 '18 at 14:45