$_GET URL from ?url=http://google.com


$_GET URL from ?url=http://google.com

我正在为我的网站制作重定向脚本,我使用 htaccess 重写 URL,使其看起来更好。

例如。 http://localhost/r/http://google.com是 URL,但是当我打印值时,它显示为这样http:/google.com.
缺少一个/,我该如何解决?

编辑:
重写规则:
RewriteRule ^r/(.*)/$ /system/offsite/redirect/index.php?url=$1 [L]

感谢您的任何帮助:)

此行为是由于 Apache 在映射之前删除空路径段。但您可以通过以下THE_REQUEST访问原始请求的 URI 路径:

RewriteCond %{THE_REQUEST} ^GET' /r/([^' ]+)
RewriteRule ^r/ /system/offsite/redirect/index.php?url=%1 [L]

使用 php urlencode 函数

编辑:

//echo your url
echo 'http://localhost/r/'. urlencode('http://google.com');

并在您的索引.php文件中

//get your url
$url = urldecode($GET['url']);

我认为REQUEST_URI变量将具有正确的文本。像这样使用它:

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/r/(.*)$
RewriteRule ^r/ /system/offsite/redirect/index.php?url=%1 [L,QSA,NC]