Redirects when the site supports HTTP and HTTPS
I have a site that uses both HTTP and HTTPS and users often land on HTTP and eventually end up on HTTPS. I'd like to set up a test that would require a redirect and it's important that if the user was on HTTP that he gets redirected to a page HTTP and if he was on HTTPS then he'd get redirected to a page on HTTPS. Optimizely redirect option seems to require a protocol (e.g. http://site.com/something). How would I do this?
Solved! Go to Solution.
Great question. While the default functionality will hardcode the protocol ( http: or https: ), it is pretty easy to make a small change to pull the value directly from the page the user is currently on and construct the redirect URL from that.
For example, the default redirect code looks something like this when you set up a redirect with live query parameters and open up the 'Edit Code' section:
The same thing is true of redirects without the live query parameters, you just need to change line 2 instead of line 3:
Notice that window.location.protocol returns the value with the colon, so you don't need to include that in the hardcoded part of the URL.
You can get most of the variation code by just doing the default redirects, and then just make the small changes outlined here to persist the protocol across pages