【问题标题】:Rewrite rule stripping characters重写规则剥离字符
【发布时间】:2011-12-29 02:02:51
【问题描述】:

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

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

如果 url 是 http://foo.com/details/12345/http://www.bar.com/dsfkjds,PHP 会看到 http://www.bar.com/dsfkjds

我不确定这是 PHP、regex 还是 apache 问题。任何帮助表示赞赏,谢谢!

【问题讨论】:

  • 只是做一个str_replace('http:/', 'http://', $_GET['url'])

标签: php regex apache .htaccess


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-30
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多