如何在PHP中提取404错误的URL参数

问题描述:

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.

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.

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