Although I'm sure it's possible I cannot see how I would be able to do the following.
虽然我确信有可能我无法看到我如何能够做到以下几点。
Using .htaccess to point the html errors to a single error handling page (this bit not a a problem).
使用.htaccess将html错误指向单个错误处理页面(这不是问题)。
That page then checks what the error code actually was (404, 500 etc.) and displays a message according to each one.
该页面然后检查错误代码实际上是什么(404,500等)并根据每个错误代码显示消息。
I am trying to do it in a PHP environment, and it's for a minimalistic site so the less files the better.
我试图在PHP环境中这样做,它是一个简约的网站,所以文件越少越好。
This is an example of a 404 I'm producing, http://isitup.org/404, and all I want is to switch the number accordingly.
这是我正在制作的404的一个例子,http://isitup.org/404,我想要的是相应地切换数字。
2 个解决方案
#1
I always put in my .htaccess:
我总是加入我的.htaccess:
ErrorDocument 403 /error.php?error=403
ErrorDocument 404 /error.php?error=404
ErrorDocument 500 /error.php?error=500
etc for whatever errors I want, then just switch case on $_GET['error'].
对于我想要的任何错误,然后只需在$ _GET ['error']上切换大小写。
Don't think there is any more sophisticated way of doing it.
不要认为有更复杂的方法。
#2
Since you're using .htaccess to redirect errors to a custom error handler file, you can use $_SERVER['REDIRECT_STATUS']
to obtain the HTTP error code. Based on that, you can display a different message depending on the error code.
由于您使用.htaccess将错误重定向到自定义错误处理程序文件,因此可以使用$ _SERVER ['REDIRECT_STATUS']来获取HTTP错误代码。基于此,您可以根据错误代码显示不同的消息。
#1
I always put in my .htaccess:
我总是加入我的.htaccess:
ErrorDocument 403 /error.php?error=403
ErrorDocument 404 /error.php?error=404
ErrorDocument 500 /error.php?error=500
etc for whatever errors I want, then just switch case on $_GET['error'].
对于我想要的任何错误,然后只需在$ _GET ['error']上切换大小写。
Don't think there is any more sophisticated way of doing it.
不要认为有更复杂的方法。
#2
Since you're using .htaccess to redirect errors to a custom error handler file, you can use $_SERVER['REDIRECT_STATUS']
to obtain the HTTP error code. Based on that, you can display a different message depending on the error code.
由于您使用.htaccess将错误重定向到自定义错误处理程序文件,因此可以使用$ _SERVER ['REDIRECT_STATUS']来获取HTTP错误代码。基于此,您可以根据错误代码显示不同的消息。