我正在为我的网站制作一个重定向脚本,我使用htaccess来重写URL以便它看起来更好。
例如。 http://localhost/r/http://google.com
是网址,但是当我打印出的值如http:/google.com
所示。
一个/
丢失,我该如何解决?
编辑:
重写规则:
RewriteRule ^r/(.*)/$ /system/offsite/redirect/index.php?url=$1 [L]
感谢所有帮助:)
我正在为我的网站制作一个重定向脚本,我使用htaccess来重写URL以便它看起来更好。
例如。 http://localhost/r/http://google.com
是网址,但是当我打印出的值如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');
,并在你的index.php文件
//get your url
$url = urldecode($GET['url']);
我试过了,这是与urlencode()'http%3A%2Fgoogle.com'。这可能是重写规则。 – NoobiCake 2011-05-14 16:10:15
@NoobiCake:这是应该的。在'redirect.php'中解码。 – 2011-05-14 16:15:28
我认为REQUEST_URI变量都会有正确的文本。像这样使用它:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/r/(.*)$
RewriteRule ^r/ /system/offsite/redirect/index.php?url=%1 [L,QSA,NC]
也许你应该告诉我们你的重写规则。 – ceejayoz 2011-05-14 16:05:12
urlencode()/ urldecode()可能会解决该问题 – 2011-05-14 16:07:35
^r /(.*)/$期望地址末尾的/要重定向,如http:// localhost/r/http://google.com //如此删除它可能会解决您的问题 – 2011-05-14 16:10:21