简体   繁体   English

NGINX的自定义PHP错误页面不响应“?= _”

[英]Custom PHP Error Page for NGINX Not Responding To '?=_'

I've recently created a custom error page with configuration such as: 我最近用以下配置创建了一个自定义错误页面:

error_page 404 /error.php?code=404

But it seems to show up only error.php instead of error.php?code=404 . 但似乎只显示error.php而不是error.php?code=404

I've cheked the php file by accessing /error.php?code=404 in my browser and it works fine. 我通过在浏览器中访问/error.php?code=404来检查php文件,效果很好。 I am using $Get 我正在使用$ Get

Please help. 请帮忙。 Thanks a lot. 非常感谢。

From the nginx documentation it seems that you can specify only an URI of script name (or @named location), not its parameters. nginx文档看来,您只能指定脚本名称(或@named位置)的URI,而不能指定其参数。 I guess the script receives the parameters of the original URI instead. 我猜脚本代替了接收原始URI的参数。

There are several solutions/workarounds: 有几种解决方案/解决方法:

1) You need to have a separate errorXYZ.php script for each error code you want to redirect. 1)对于要重定向的每个错误代码,您需要有一个单独的errorXYZ.php脚本。

2) Or use external redirect such as http://yourserver.com/error.php?code=404 , but note that this will be defaut reply with HTTP response code 302 and the users will see the error.php location in their browser. 2)或使用外部重定向,例如http://yourserver.com/error.php?code=404 ,但请注意,这将是HTTP响应代码302的默认回复,用户将在浏览器中看到error.php位置。

3) Or URIs such as /error.php/404 and parse it inside your PHP script. 3)或诸如/error.php/404 URI,然后在您的PHP脚本中进行解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM