2011-05-14 126 views
2

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

例如。 http://localhost/r/http://google.com是网址,但是当我打印出的值如http:/google.com所示。
一个/丢失,我该如何解决?

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

感谢所有帮助:)

+0

也许你应该告诉我们你的重写规则。 – ceejayoz 2011-05-14 16:05:12

+0

urlencode()/ urldecode()可能会解决该问题 – 2011-05-14 16:07:35

+0

^r /(.*)/$期望地址末尾的/要重定向,如http:// localhost/r/http://google.com //如此删除它可能会解决您的问题 – 2011-05-14 16:10:21

回答

1

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

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

使用PHP urlencode功能

编辑:

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

,并在你的index.php文件

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

我试过了,这是与urlencode()'http%3A%2Fgoogle.com'。这可能是重写规则。 – NoobiCake 2011-05-14 16:10:15

+0

@NoobiCake:这是应该的。在'redirect.php'中解码。 – 2011-05-14 16:15:28

1

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

Options +FollowSymlinks -MultiViews 
RewriteEngine on 

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