Skip to main content
January 29, 2015
Question

Dynamic Redirects

Our team is trying to redirect landing pages while keeping the URL parameter data within the querystring. If we are using one landing page for a variety of different networks like, Facebook, Twitter, Website, etc. How would we keep this information through a redirect?

Ex. A person is on Facebook and sees an ad for our content on this landing page:
 
Info.company.com/video?networks=facebook&mostrecentnetwork =facebook
 
And we want the redirect to go to our website:
 
company.com/on-demandvideo
 
We have this landing page on several other sites as well and would like to dynamically populate the parameter info for each one. Do we have to make a redirect for each channel?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Kenny_Elkington
Adobe Employee
Adobe Employee
January 29, 2015
Hey Danny,

Check out example 2 here: http://developers.marketo.com/documentation/websites/forms-2-0/

What you'll want to do is grab the querystring before changing location.href like this:

var qs = window.location.href.split("?");

Then append it to your desired location during the redirect:

location.href = "//www.example.com" + qs;

EDIT: See below for a better answer.
Translate
SanfordWhiteman
Level 10
January 30, 2015
@Kenny E if you're trying to keep the QS and pass it verbatim to another page, your approach isn't correct:
  • String::split() returns an array and by defintion does not include the "?" character.
  • It's not necessary to parse location.href at all: location.search already contains the query string.
  • Using scheme-relative URL "//..." means you will never redirect from http:// to https:// or https:// to http://, which is a big assumption.

The correct way is:
 
window.location.href  = "http://redirect.example.com" + window.location.search;

However from the OP's example he isn't using the original QS but rather massaging it into a different hostname and path.  There isn't any magical way to do this except a series of case statements or regexes.
Translate