当浏览器请求以下网址
http://test.localhost/mobile.html?page=online&option=test&_ga=2.145898866.737559230.1531785796-1355088823.1529293502
htaccess文件规则
RewriteRule ^(.*)\.html$ index.php?page=$1
将URL修改为
http://test.localhost/index.php?page=mobile
在index.php文件中,具有以下echo语句。
echo "Request URI:" . $_SERVER['REQUEST_URI'] . "<br/>";
echo "Query String:" . $_SERVER['QUERY_STRING'] . "<br/>";
它显示以下输出
请求URI:
http://test.localhost/order-online/order.html?_ga=7.145874566.73777770.1531785796-135578823.152927502 Query String:page=mobile
请求URI显示原始请求,如何获取重写的请求URI http://test.localhost/index.php?page=mobile
答案 0 :(得分:1)
在您的PHP代码中,您可以使用以下代码来获取重写的URI:
$uri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];