[英]How to extract URL parameters on 404 Error in PHP
I have my htaccess redirecting to a error404.php but I want that PHP file to be able to extract the original url parameters. 我将htaccess重定向到error404.php,但我希望该PHP文件能够提取原始url参数。
For example: 例如:
http://mywebsite.com/unknownfile.php?param1=value1¶m2=value2
I've tried $_GET['param1']
but that's empty. 我已经尝试过
$_GET['param1']
但这是空的。 The $_SERVER['PHP_SELF']
just shows error404.php $_SERVER['PHP_SELF']
仅显示error404.php
Many thanks in advance. 提前谢谢了。
You can access original URL via $_SERVER["REQUEST_URI"]
. 您可以通过
$_SERVER["REQUEST_URI"]
访问原始URL。
For example: requesting URL /hihi/meow?key=rumba
which does not exists. 例如:请求的URL
/hihi/meow?key=rumba
不存在。 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. $_SERVER["REQUEST_URI"]
将具有该字符串,您可以使用parse_url()函数对其进行解析以将其拆分为多个部分,并使用其他函数(例如explode()
来获取各个查询的串连参数)。
如果您重定向,此信息将仅出现在$_SERVER['HTTP_REFERER']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.