0

so I'm using a redirect link for going from a landing page to an offer page, but in the middle, I want to go to a redirect page that is populated according to parameters I send, for example. my url is:

http://domain.com/file.php?param1={param1}&param2={param2}&param3={param3}&param4={param4}

and in file.php I will have the following:

<html><head>
     <script>
     function getURLParameter(name) {
         return decodeURI(
                (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] || ''
            );
        }
</script>
    <script>
    var param1 = getURLParameter('param1'); 
    var param2 = getURLParameter('param2');
    var param3 = getURLParameter('param3');
    var param4 = getURLParameter('param4');

    var url = 'http://domain2.com/'+param1+'?param2='+param2+'&param3='+param3+'&param4='+param4';

    window.location.replace(url);           
  </script>
</head>
<body>

</body></html>

now, I have been trying to use

header('Location: '.$newURL);

but I wasn´t able to make it work like that, the thing is that I would like to be able to manage the redirection to "domain2" seamsless, as in the middle I'm losing track of some information that I would like to have.

in the normal process of tracking url (domain.com) --> to destination url (domain2.com) there is no problem, the thing is that I need to add file.php in the middle (which is in another domain) because I have an script that needs to be executed only there.

thank you in advance

1 Answer 1

1

May be you can use usual $_GET to get the params from URL string? And then in php you can do anything you want. Like: http://domain.com/file.php?param1={param1}&param2={param2}&param3={param3}&param4={param4}

in file.php:

$param1 = $_GET['param1'];

$param2 = $_GET['param2'];

and etc. Then you can set header function with needed options Hope that helps you

Sign up to request clarification or add additional context in comments.

7 Comments

I understand, but I see that this achieves the same result of what I already have.. or am I missing something?
it seems you've missed something at domain2 URL. domain2.com/'+param1+'?param2='+param2+ .... Param1 should be like this ?param1=param1 ... or may be you've missed / after param1: 'domain2.com/'+param1+'/?param2='+param2+ .....
I don't know your target URL structure -so can't explain if you missed '/' or should set param1 as parameter of URL not as the only +param1+
no, the structure is correct, the url is made by that parameter, so is correct.
Well, if we use the url1 like this: domain1.com/file.php?param1=services , content of file.php is: $param1 = $_GET['param1']; $new='google.com/'.$param1; header('location:'.$new); , then as a result we'll get the redirect from our first domain to google.com/services . It seems like yours...and it's working.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.