Rich-text Reply

Regex Targeting & URL Redirect - Need some help

andriym 07-09-15
Accepted Solution

Regex Targeting & URL Redirect - Need some help

[ Edited ]

Hello to the Optimizely community!


I'd like to run a split URL test with the setup below. This was fairly straightforward on my old AB testing platform, but I want to make sure I set it up correctly on Optimizely as I'm still getting familiarized with it. I would love some help with this :


1) This a split URL test, not a visual editor test

My original pages for Variation #1 share the same layout template, but their URLs vary quite a bit:

Which means I'll have to target them with regex (since there's no underlying pattern)


2) I've built about 20 pages I'd like to the above to redirect to during the test, at "originalurl2": > > http://www.domain.comteach-english-in-vietnam2 > http://www.domain.comteaching-jobs-in-hong-kong2


How do I make sure both that the regex targeting is working properly and the redirect appends "2" to the end of each unique URL it's redirecting from. Hopefully without messing up my data or creating redirect loops? I've seen code snippets on these forums for similar scenarios, but mostly for Variation B URLs having a different query string parameter at the end - not a different ending for the URL itself, like in my use case.


Thank you so much for input! I want to do this right and not break the test so I would really appreciate some advice.

Level 3

andriym 07-10-15

Re: Regex Targeting & URL Redirect - Need some help

[ Edited ]

Update: Here's how I went about it. I would love it if someone from Optimizely could confirm that the custom redirection code and general setup are right ...


I set the URL targeting to exact and entered added each of my different Original Variation URLs in full (adding a new line for each one with the + icon): , /teaching-jobs-in-hong-kong , and so on


I then added a Variation #1 and added this to the code to append "2" to each URL upon redirect:


/* _optimizely_redirect=http://custom */
var url = window.location;
var redirect_url = 'http://' + url.hostname + url.pathname + '2' +;
window.location = redirect_url;

Each of my pages seems to be redirecting pageurl > pageurl2 and the stats look OK so far. But I've still got a nagging feeling I made a mistake somewhere?

Level 3
JDahlinANF 07-10-15

Re: Regex Targeting & URL Redirect - Need some help

This is the same way I would have done it.


I seldom use "exact match", so I would double-chech that the URL targeting allows for hitting the "A" pages with parameters.  If that fails, you could change them to "substring" and then add an exclusion line for "exclude URLs that contain the number 2"

andriym 07-14-15

Re: Regex Targeting & URL Redirect - Need some help

While technically this turned out to work, it creates issues if you have other custom code you'd like to add to your variations Smiley Sad - check out this thread. I'm stil going to "accept this solution" because it technically solved what I was initially trying to do.

Level 3