How to extract URL parameters on 404 Error in PHP

2019-09-04 14:50发布

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.

2条回答
我命由我不由天
2楼-- · 2019-09-04 15:47

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

查看更多
放我归山
3楼-- · 2019-09-04 15:48

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.

查看更多
登录 后发表回答