我使用自己的 MVC 系统已经有一段时间了,它运行得很好!
我在我的 .htaccess 中使用它
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]
现在,当页面(控制器)不存在时,我重定向到 /error(在index.php文件中)。
但有些情况下,文件夹中的图片会被删除,但仍会打印在html页面中。这将自动使浏览器调用不存在的图片(因此它将调用/error页面)
现在我想做的是,当一张图片或任何文件(我猜除了 php、html 文件)我想重定向到 404 文件而不是 /error。
我确信这个问题可以在 .htaccess 文件中解决,但我和 Apache 目前还不是好朋友。有谁是 Apache 的朋友吗?
Thanks!
例如,假设您的图像位于公共子文件夹中/images
in http://example.com/images/img.png
,您可以更改规则以完全排除此子目录,然后添加错误文档。该 .htaccess 应该位于您的 www 根目录中。
RewriteEngine On
#If the file does not exist, and the url doesn't start with /images
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/images
RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]
#If the rule above didn't match, and the file does not exist, use the ErrorDocument
ErrorDocument 404 /404.php
See
- 错误文档的文档 http://httpd.apache.org/docs/2.2/mod/core.html#errordocument
- mod_rewrite 的文档 http://httpd.apache.org/docs/current/mod/mod_rewrite.html
-
Apache 的免费友谊优惠券 http://ode.apache.org/img/asf.png(可能会或可能不会过期)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)