Rich-text Reply

Redirect Problems

odower 06-28-14
Accepted Solution

Redirect Problems

i have thousands of pages at:

https://mysite.com/courses/exampletitleofcourse

i have all those same pages, but with a new template i want to direct users too at:

https://mysite.com/video/exampletitleofcourse

so essentially all that changes when users hit any one of a thousand of the /courses/ pages....it just flips out the word courses with video and keeps the rest of the remaining URL. 

I would like to set up a test where I direct a percentage of traffic from /courses/* to that same piece of content at /video/*.

Please help. Thank you

 

PS: I've been sent the following as answers but none actually works.  

 

https://help.optimizely.com/hc/en-us/articles/200040675#modify

 

and then i've been given this code, but it appended /video/ and so /courses/ was still in the url, thus breaking the new page. 

 

/* _optimizely_redirect=http://custom */

if (navigator.userAgent.match("Firefox\/(3\.6\..)") || navigator.userAgent.match("MSIE") || navigator.userAgent.match("Safari")) { 

var path = window.location.pathname;

var params = window.location.search;

var redir_url = "http://" + window.location.host + "/video" + path + params

window.location.replace(redir_url);

 

} else { 

var path = window.location.pathname;

var params = window.location.search;

var redir_url = "http://" + window.location.origin + "/video" + path + params

window.location.replace(redir_url);

};

Level 2

MartijnSch 06-30-14
 

Re: Redirect Problems

It's a bit nasty but why don't you just replace the string /courses/ with /video/ in the URL by using the replace function in JS (http://www.w3schools.com/jsref/jsref_replace.asp). It makes it easier to make sure the page gets redirected to the right location.
odower 06-30-14
 

Re: Redirect Problems

Thanks! But isn't that what I'm paying Optimizely over $200/month for?
Level 2
MartijnSch 06-30-14
 

Re: Redirect Problems

You could request this as a feature here: http://community.optimizely.com/t5/Product-Ideas/idb-p/product-ideas, but besides that you pay Optimizely for the platform, although you're still pretty lucky with your $200 ;-). Probably not to have specific use cases fixed.
odower 06-30-14
 

Re: Redirect Problems

So replacing /old/ to /new/ but keeping the rest of the URL parameters is a specific use case?
Level 2
Brett 06-30-14
 

Re: Redirect Problems

If all you need to do is change /courses/ to /video/ that should be simple to do with Optimizely. We just need to write some javascript to remove /courses/ and place /video/ in its place.

Here is the coded I would use within Optimizely:

/* _optimizely_redirect=http://custom */
window.host = window.location.host
window.query = window.location.search
window.change = window.location.pathname.replace(/courses/i, 'video');
window.new_url = window.location.protocol + '//' + window.location.host + window.change + window.query
window.location.replace(new_url)

This will also account for any query parameters that might have the word courses in them as well. Just put that code into the variation code of the redirect variation and you should be good to go.

Give it a shot and let me know if it doesn't work for you.
Optimizely
Noah 07-10-14
 

Re: Redirect Problems

Hey Odower,

 

Were you able to find a solution for this use case? This is exactly what I'd like to test in some future experiments and I was hoping Optimizely could do it out of the box.

 

Testing individual pages 1:1 using Redirects is good, but I'd love to use some kind of substring/regex to split traffic to two different directories and test hundreds of templated pages.

 

Thanks!

Noah

Noah Shunfenthal
Marketing Automation & Optimization
Level 2
odower 07-10-14
 

Re: Redirect Problems

Unfortunately I've gotten no step by step help.  

 

They custom 'fixed' it for me, which I will document here today.  

Level 2
Amanda 07-11-14
 

Re: Redirect Problems

[ Edited ]

Hey @odower - I am really interested to hear the way that you fixed it. Out of curiousity, did you try @brett 's suggestion above? It looks like that solution should have worked so if it did not, we would definitely like know about it. Thanks in advance! 

Optimizely
Gary 07-16-14
 

Re: Redirect Problems

Hi @odower , @Noah reached out to OptiSupport and referenced this article, so I gave him a very simply solution for this scenario, which I can translate for your case here:

/* _optimizely_redirect=http://custom */
window.location.href.replace(/[oldPart/,'NewPart');

For you, this old part would be the string 'courses' and new part be 'video', so this should look as such (please note, the slashes around the 'oldPart' are to make this a regular expression search and need to be kept:

/* _optimizely_redirect=http://custom */
window.location.href.replace(/courses/,'video');

This code needs to be placed inside the Edit Code section (https://help.optimizely.com/hc/en-us/articles/200039835-Edit-Code) of your experiment's variation.
- Gary
Optimizely - Turning the World's data into action
Optimizely
odower 03-13-15
 

Re: Redirect Problems

Gary,

I'm back at this with type of issue. There really isn't a way to do this just in the tool by saying "redirect all /video/ templates to /path/ templates?

Andy
Level 2
Gary 03-17-15
 

Re: Redirect Problems

[ Edited ]

Hi @odower,

Can you post the experiment ID# on here to inspect?
As for there being a place in the tool that does this, you are right that we don't have this as it requires custom code in the code editor.

 

The concept outlined in my response above should work for you, but I'd be happy to look into the specific experiment too.

Here's the code that you should be able to modify according to your needs and paste into the code editor. 

 

/* _optimizely_redirect=http://custom */

window.location = window.location.href.replace('/video/', '/path/');

 

This takes a URL -- for example www.example.com/product/video/1234 and would redirect it to www.example.com/product/path/1234

- Gary
Optimizely - Turning the World's data into action
Optimizely