的.htaccess显示404页,改写? [英] .htaccess show 404 page with rewrite?

查看:118
本文介绍了的.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

谢谢!

这篇关于的.htaccess显示404页,改写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆