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

2023-09-02 20:40:31 作者:花生日记

我有我的htaccess重定向到一个error404.php,但我想在PHP文件能够提取原始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.

例如:

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

我已经试过 $ _ GET ['参数1'] 但这是空的。该 $ _ SERVER ['PHP_SELF'] 只显示error404.php

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

在预先感谢。

推荐答案

您可以通过 $访问原始网址_ SERVER [REQUEST_URI]

例如:请求网址 /日冰/喵键=伦巴不存在。该 $ _ SERVER [REQUEST_URI] 将有一个字符串,你可以用的 parse_url()函数分裂成几部分,并使用其他功能(如爆炸()来获得个人的查询串参数。

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.