Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $\u从中获取URL?URL=http://google.com_Php_.htaccess - Fatal编程技术网

Php $\u从中获取URL?URL=http://google.com

Php $\u从中获取URL?URL=http://google.com,php,.htaccess,Php,.htaccess,我正在为我的站点制作一个重定向脚本,我使用htaccess重写URL,使其看起来更好 例如,http://localhost/r/http://google.com是URL,但当我打印该值时,它显示如下http:/google.com 缺少一个/,如何修复 编辑: 重写规则: RewriteRule^r/(.*)/$/system/offsite/redirect/index.php?url=$1[L] 感谢您的帮助:)使用php函数 编辑: //echo your url echo 'http

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

例如,
http://localhost/r/http://google.com
是URL,但当我打印该值时,它显示如下
http:/google.com

缺少一个
/
,如何修复

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

感谢您的帮助:)

使用php函数

编辑:

//echo your url
echo 'http://localhost/r/'. urlencode('http://google.com');
在index.php文件中

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

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


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

Options +FollowSymlinks -MultiViews
RewriteEngine on

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

也许你应该向我们展示你的重写规则。urlencode()/urldecode()可能会解决这个问题^r/(.*)/$希望在地址末尾有一个/被重定向,就像这样删除它可能会解决你的问题我已经尝试过了,这是使用urlencode()
http%3A%2Fgoogle.com
。这可能是重写规则。@noobicke:应该是这样的。在
redirect.php
中对其进行解码。
Options +FollowSymlinks -MultiViews
RewriteEngine on

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