Micku
Micku

Reputation: 550

How to pass url as a value in a link using htaccess?

I want to pass a url through a link

My htaccess code is :

RewriteRule ^info/(.*)$ folder1/page1.php?url=$1 [L]

But my result is :

$_GET['url'] = http:/stackoverflow.com (one slash is missing , http:/)

I need $_GET['url'] as http://stackoverflow.com

How is it possible using htaccess?

Can someone help me plz.....

Upvotes: 0

Views: 198

Answers (4)

Thomas Lomas
Thomas Lomas

Reputation: 1553

If push comes to shove:

$_GET['url'] = str_replace('http:/', 'http://', $_GET['url']);

Upvotes: 0

anubhava
anubhava

Reputation: 785128

Using RewriteRule to match URI will not work because Apache will strip multiple slash into 1. Here is the code that makes it possible using %{THE_REQUEST}:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+info/([^\s\?]+) [NC]
RewriteRule ^ index.php?url=%1 [L,QSA]

Upvotes: 0

safarov
safarov

Reputation: 7804

its not possible, / slash is url separetor. You must encode it before use as parameter. For example : site.com/info/http%3A%2F%2Fstackoverflow.com

$url = isset($GET['url']) ? urldecode($GET['url']) : 'default';

Or better dont use http://. And site.com/info/stackoverflow.com. In php:

$url = isset($GET['url']) ? 'http://'.$GET['url'] : 'default';

Upvotes: 1

Willem D'Haeseleer
Willem D'Haeseleer

Reputation: 20180

I think Xzibit has a valid point on this:

http://cdn.memegenerator.net/instances/400x/18286577.jpg http://cdn.memegenerator.net/instances/400x/18286681.jpg

short story: use urlencode when you want to embed a url inside a link, i think it will fix your problem.

http://php.net/manual/en/function.urlencode.php

Upvotes: 4

Related Questions