且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP:如何获取已使用mod_rewrite重写的URL?

更新时间:2023-02-24 12:38:01

您可以轻松地重新创建它. $_SERVER['PHP_SELF']仍会为您提供脚本的正确文件名.这应该可以解决问题:

You can recreate it pretty easily. $_SERVER['PHP_SELF'] will still give you the correct file name for the script. This should do the trick:

$url = $_SERVER['PHP_SELF'];
$parts = array();
foreach( $_GET as $k=>$v ) {
    $parts[] = "$k=" . urlencode($v);
}

$url .= "?" . implode("&", $parts);

$url现在将成为您要查找的URL.

$url will now be the URL you're looking for.

@carpereret的答案要好得多.改为支持他

@carpereret's answer is far better. Upvote him instead