htaccess的和定制的ErrorDocument不同文件类型 [英] .htaccess and custom ErrorDocument for different file types

查看:215
本文介绍了htaccess的和定制的ErrorDocument不同文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有可能使用mod-rewrite随着减速的ErrorDocument根据请求文件的类型定制的错误页面。

I'm wondering if it's possible to use mod rewrite along with the ErrorDocument deceleration to customize the error pages depending on what type of file is requested.

例如不存在的HTML或PHP文件请求Apache将给予很好的自定义的HTML页面。

For example a non-existent html or php file is requested Apache will give nice custom HTML page.

但是,如果不存在的图像,JS,CSS等...文件请求然后Apache将发球出一个基本的HTML文件与在其上仅一个链接。

But if a non-existent image, js, css, etc... file is requested then Apache will serve out a basic html file with only a link on it.

这种行为的一个很好的例子就是Facebook的。尝试请求伪造的JavaScript文件,您将收到一个不同的页面,然后如果你请求一个不存在的php文件。

A good example of this behavior is Facebook. Try requesting a bogus JavaScript file, you will receive a different page then if you were to request a non-existent php file.

推荐答案

最后同时使用的ErrorDocument和规则集这工作,因为PHP页面抛出一​​个404未找​​到适合我的组合。

Ended up using a combination of both ErrorDocument and RewriteRules this works because the php page throws a 404 Not Found for me.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*(?<!.js|.css|.ico|.txt|.bmp|.gif|.png|.jpeg|.jpg)$ /error/404.php [L]

ErrorDocument 404 /404_basic.html

这篇关于htaccess的和定制的ErrorDocument不同文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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