问题描述:

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 192.168.0.123/greet.html to 192.168.0.123/greet.php.


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

 RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)$ $1.php [NC,L]


When I type http://192.168.0.123/greet 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
相关阅读:
Top