重写规则剥离字符

时间:2011-12-29 02:02:51

标签: php regex apache .htaccess

我的.htaccess文件中有这个重写规则,但在PHP中获取url($ _GET ['url'])时,它从http://

中删除了一个斜杠
RewriteRule ^details/([0-9]+)/(.*)$ details/index.php?urlid=$1&url=$2 [L,QSA]

如果网址为http://foo.com/details/12345/http://www.bar.com/dsfkjds,则PHP会看到http:/www.bar.com/dsfkjds

我不确定这是PHP,正则表达式还是apache问题。感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:2)

这是Apache规范化路径段。 RewriteRule检测或更改它为时已晚。

但是,您可以在$_SERVER["REQUEST_URI"]中查看原始请求网址,然后再次应用正则表达式以查看完整参数。

preg_match("#^/+details/+([0-9]+)/+(.*)$#", $_SERVER["REQUEST_URI"], $m)
and $url = $m[2];