使用Apache本机触发自定义500错误

时间:2018-06-21 21:08:58

标签: apache error-handling

我正在使用Apache 2.4,并且启用了多个虚拟主机。其中一些使用重写模块,但不是全部。我想智能化虚拟主机配置文件,以便在该模块丢失时触发500错误。该错误应仅针对实际使用重写模块的虚拟主机触发,而不会破坏其他主机。我想使用尽可能少的技术,即没有PHP,没有JS,没有可能在新安装的Apache上被禁用的Apache模块。

我设法找到了一个可行的解决方案,但它的目的太复杂了,它取决于javascript和别名模块。

以下是触发错误的配置:

<IfModule !mod_rewrite.c>
    ErrorDocument 500 /error.html

    <Directory /home/myself/public_html>
        Require all granted
    </Directory>

    <Files "error.html">
        <If "-z %{ENV:REDIRECT_STATUS}">
            RedirectMatch 500 ^/error.html$
        </If>
    </Files>

    <FilesMatch "(?<!error\.html)$">
        Redirect /error.html?message=Mod%20rewrite%20is%20not%20installed.
    </FilesMatch>
</IfModule>

这是我不想要的HTML文件:

<html>
<body>
    <h1>Apache Error</h1>
    <p><script>document.write(decodeURIComponent((new RegExp("[?&]message(?:=([^&#]*)|&|#|$)")).exec(window.location.href)[1]));</script></p>
</body>
</html>

0 个答案:

没有答案