开发者

How to extract URL parameters on 404 Error in PHP

开发者 https://www.devze.com 2023-03-22 16:57 出处:网络
I have my htaccess redire开发者_JS百科cting to a error404.php but I want that PHP file to be able to extract the original url parameters.

I have my htaccess redire开发者_JS百科cting 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']

0

精彩评论

暂无评论...
验证码 换一张
取 消