How to extract URL parameters on 404 Error in PHP

半腔热情 提交于 2019-12-13 06:36:03

问题


I have my htaccess redirecting to a error404.php but I want that PHP file to be able to extract the original url parameters.

For example:

http://mywebsite.com/unknownfile.php?param1=value1&param2=value2

I've tried $_GET['param1'] but that's empty. The $_SERVER['PHP_SELF'] just shows error404.php

Many thanks in advance.


回答1:


You can access original URL via $_SERVER["REQUEST_URI"].

For example: requesting URL /hihi/meow?key=rumba which does not exists. The $_SERVER["REQUEST_URI"] will have that string, which you can parse with parse_url() function to split into parts and use other functions (like explode() to get to individual query strung parameters.




回答2:


If you redirect this info will only be present in $_SERVER['HTTP_REFERER']



来源:https://stackoverflow.com/questions/6823721/how-to-extract-url-parameters-on-404-error-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!