PHP:如何获取已使用mod_rewrite重写的URL? [英] PHP: How can I get the URL that has been rewritten with mod_rewrite?
本文介绍了PHP:如何获取已使用mod_rewrite重写的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,如果我将/category/topic/post/
重写为/index.php?cat=1&topic=2&post=3
,如何使用PHP获得/index.php?cat=1&topic=2&post=3
?
For example, if I rewrite /category/topic/post/
to /index.php?cat=1&topic=2&post=3
, how can I get /index.php?cat=1&topic=2&post=3
using PHP?
推荐答案
您可以轻松地重新创建它. $_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
这篇关于PHP:如何获取已使用mod_rewrite重写的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文