的.htaccess显示404页,改写?

问题描述:

我有本质上的删除在Web浏览器中的文件扩展名(从使用example.php示例).htaccess文件。这里的code:

I have a .htaccess file that essentially "removes" the file extension in the web browser (from example.php to example). Here's the code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

基本上,如果该文件(约)是找不到的,它增加了PHP扩展(about.php)。我想(如果找不到该文件仍然)将用户重定向到404.php。因此,如果用户负载/第1页,并page1.php中不存在,它重定向到404页。我说这code到的.htaccess:

Basically, if the file (about) isn't found, it adds the .php extension (about.php). I want to (if the file still isn't found) redirect the user to 404.php. So if the user loads /page1, and page1.php doesn't exist, it redirects to the 404 page. I added this code to the .htaccess:

ErrorDocument 404 /404.php

在它自己的,这code重定向到404页。但是,当我拥有整个code ...

On it's own, this code will redirect to the 404 page. But when I have the entire code...

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

ErrorDocument 404 /CWTC/404.php

...它只是显示了一个500内部服务器错误。

...it just shows a "500 Internal Server Error".

有谁知道我在做什么错了?

Does anyone know what I'm doing wrong?

谢谢!

这解决了我的问题:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA]

ErrorDocument 404 /404.php

谢谢!