.htaccess - PHP redirect to a link in URL

974

For my affiliate links I want them to be redirect through an intermediate page (calling it routers) to measure certain datas and efficiency.

Assuming I have my affiliate link aswww.affiliate.in?id=sdff&para=dshjgsf&aaffid=JAHAJEE and an intermediate pagewww.mysite.com/redirect.php?someid=1&otherid=2&url=THE_URL_TO_REDIRECT_TO

My problem is that affiliate links have? and& and so when I use my affiliate link in this router URL, I am unable to get complete$_GET[url] ! Any help on how to do it with these additional parameters intact ?

867

Answer

Solution:

Encode the Url

string urlencode ( string $str )

This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.

pass the THE_URL_TO_REDIRECT_TO to the function

as

 urlencode(THE_URL_TO_REDIRECT_TO )

php.net

966

Answer

Solution:

Encode your url and use it (urlencode)

<?php 
$afurl = urlencode('http://www.affiliate.in?id=sdff&para=dshjgsf&aaffid=JAHAJEE');
$url = 'http://www.yourdomain.com/redirect.php?someid=1&otherid=2&url='.$afurl;
echo $url;
?>

this urlencode encrypt all of your special characters.

if you want to get url using htacces use the following link. This will guide you lot.

htaccess url as parameter

The major issue i think you get the URL in this format[a-zA-Z0-9|] you need to change it to(.*)

562

Answer

Solution:

you can get the values passed in the url by

$_SERVER['QUERY_STRING']

People are also looking for solutions to the problem: wordpress - Breaking down a large String in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.