Rich-text Reply

Redirecting site experiment from www to www2

RommanInc 04-22-15
Accepted Solution

Redirecting site experiment from www to www2

 

We are testing our new responsive design to maintain rankings now that Google is penalizing non-mobile friendly sites.  We have our original site at www.hookah-shisha.com and the new responsive version at www2.hookah-shisha.com.

 

All of the Url strings are identical, so we wanted to funnel traffic through both and monitor conversions and page views as the visitors go through the checkout process.

 

How do I set up the test so that when a customer lands on any page, for example https://www.hookah-shisha.com/c-2-hookahs-hookah-pipes.html, they go to https://www2.hookah-shisha.com/c-2-hookahs-hookah-pipes.html?  We would like the redirect to work for every page on the site and visitors to land on the new site with the same url substring.

 

My last attempt sent everyone to the homepage of www2, which I assume confused a lot of visitors and skewed our test results.

Amanda 04-22-15
 

Re: Redirecting site experiment from www to www2

Great question. This is possible with just a tiny bit of custom code. Just open your variation and click edit code. Enter the following

 

/* _optimizely_redirect_no_cookie=http://www.example.com */
window.location.replace(window.location.href.replace("www.hookah-shisha.com","www2.hookah-shisha.com "));

This code takes the first arugment and replaces it with the second. In this instance, it replaces the URL with www2, but keeps the rest of the URL the same. 

 

Here's another very similar post that describes this as well: https://community.optimizely.com/t5/Using-Optimizely/Redirect-Problems/m-p/9935#M2797

 

Do you want to give this a go and let us know if it works for you?  You'll want to set your URL targeting up to be a substring match to hookah-shisha.com to ensure that the experiment runs sitewide. 

Optimizely

Re: Redirecting site experiment from www to www2

[ Edited ]

Hi there!

 

RommanInc and I actually worked offline on this implementation and I wanted to share the custom redirect code we ended up implementing! It's slightly different from what Amanda posted above, but works just the same.

 

Here is what Optimizely's standard redirect code looks like:

 

 

/* _optimizely_redirect=https://www2.hookah-shisha.com */
var _optly={redir:document.createElement("a")};
_optly.redir.href="https://www2.hookah-shisha.com";
_optly.cur=window.location.search;
if (_optly.cur) {_optly.redir.search=_optly.redir.search ? _optly.cur + "&" + _optly.redir.search.slice(1) : _optly.cur;}
window.location.replace(_optly.redir.href);

 

We made two changes to this code: (SEE BELOW)

 

 

1) We changed the tag to specify "custom." (LINE 1)

2) We added "+ window.location.pathname"(LINE 3) in order to enable the redirect to work across all the URLs associated with the site. i.e. "https://www.hookah-shisha.com/example" will redirect to "https://www2.hookah-shisha.com/example"

 

 

/* _optimizely_redirect=http://custom */
var _optly={redir:document.createElement("a")};
_optly.redir.href="https://www2.hookah-shisha.com" + window.location.pathname;
_optly.cur=window.location.search;
if (_optly.cur) {_optly.redir.search=_optly.redir.search ? _optly.cur + "&" + _optly.redir.search.slice(1) : _optly.cur;}
window.location.replace(_optly.redir.href);

 

**In this situation, the "window.location.pathname" is "/example". Without this custom change ("+ window.location.pathname"), all pages would redirect to the home page. For instance, "https://www.hookah-shisha.com/example" would redirect to "https://www2.hookah-shisha.com"**

 

Another important thing to mention: This custom redirect code worked because all the pathnames were identical in this situation for the original and redirect. Sometimes it can be more complicated, if for example, "https://www.hookah-shisha.com/example" is trying to redirect to "https://www2.hookah-shisha.com/example-page." That would require different logic and different custom code.

 

Furthermore, as Amanda mentioned, if trying to create a site-wide redirect. (i.e. ALL "www" pages to be redirected to "www2" pages), it's important to set up a SUBSTRING match so that the experiment runs on every page with this substring: "https://www.hookah-shisha.com." For more information on URL targeting, click on the link above.

 

Happy Testing! Smiley Happy

 

 

Best,

 

 

Amy Herbertson
Customer Success

Re: Redirecting site experiment from www to www2

Hey Community!

Here are additional code snippets for different redirect implementations:

http://developers.optimizely.com/samples/#redirect---add-query-parameter-to-url

Best,
Amy
Amy Herbertson
Customer Success