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.

5
  • Try and add RewriteCond %{REQUEST_FILENAME} !-d as well. Commented Sep 18, 2018 at 13:09
  • Have to ask, are you using Apache? Commented Sep 18, 2018 at 14:47
  • yes ,apache2 ubuntu 16.04 Commented Sep 18, 2018 at 15:07
  • Of course. The second screen shot even says so :-) Missed that. And you have mod_rewrite enabled? And you have restarted the apache server after it was installed? Commented Sep 18, 2018 at 15:10
  • ypz, mod_rewrite already enabled Commented Sep 18, 2018 at 15:12

2 Answers 2

1

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] 
Sign up to request clarification or add additional context in comments.

Comments

-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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.