

apache - .htacccess simple rewrite to remove file extension not working - gives error 404 not found


I'm coding on my new RaspberryPi. I tried to use .htaccess to remove the .php from a file called 'greet'.

I installed apache2: "sudo apt-get install apache2

Enabled the rewrite module using: "sudo a2enmod rewrite"

I have also changed the permission to override standard website configs.

I know my rewrite module is working, because I tried the following it:

RewriteEngine On

RewriteRule ^greet.html$ greet.php

which successfully redirects to

However the following code to remove the .php file extension doesn't seem to be working for me:

 RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f


When I type into my browser I don't get the greet.php file. Instead I end up on a 404 Not Found page.

I can't figure out what I am doing wrong.


You can try your rule this way.

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

Why aren't you using multiviews to handle this? If you don't have a lot of complicated rewrite rules, you could just have mod_negotiation handle these extensions for you. Just need to turn it on

Options +Multiviews