开发者

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

I'm making a redirect script for my site, I use htaccess to rewrite the URL so it looks nicer.

eg. http://localhost/r/http://google.com is the URL, but when I printing the value it shows up like this http:/google.com.

One / is 开发者_JAVA技巧missing, how can I fix that?

Edit:

Rewrite rule:

RewriteRule ^r/(.*)/$ /system/offsite/redirect/index.php?url=$1 [L]

Thanks for any help :)


This behavior is due to Apache that removes empty path segments before mapping it. But you can access the original requested URI path via THE_REQUEST:

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


Use php urlencode function

EDIT:

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

and in your index.php file

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


I think REQUEST_URI variable will have correct text. Use it like this:

Options +FollowSymlinks -MultiViews
RewriteEngine on

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜