Questions? Call (860)407-2687
find us on:


Multiple Web URL Redirect Scripts For JS/

short url:

URL Redirect Scripts For Javascript And

Click to Play Video About Redirection Scripts For JS And
  • Javascript & PHP Url Redirect Scripts
  • Where to Place Javascript Multiple Url Redirect
  • PHP Multiple Url Redirection
  • Where to Place PHP Multiple Url Redirect
  • Need Help with Javascript or PHP Multiple Url Redirect Code?

Javascript & PHP Url Redirect Scripts

Here are two versions of the same script, one in php and the other in javascript. This script allows you to A/B split test multiple urls for conversions. Every time a visitor comes to your web page with this script, the script randomly chooses one of the redirect urls. Over a period of time you will be able to see which of the urls is producing the most conversions or sales.

sel
javascript
 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
// The list of urls you wish to redirect One per line. Comma after each one EXCEPT the last url in the list
var URLlist = ["http://AnyURLorAffiliateLinkHere.com/example1",
"http://AnyURLorAffiliateLinkHere.com/example2",
"http://AnyURLorAffiliateLinkHere.com/example3",
"http://AnyURLorAffiliateLinkHere.com/example4"];
 
// Amount of time or delay before the redirect. 0000 mean no delay whatsoever.
// Change to 1000 for one second delay, 2000 for two second delay, etc.
var reDelay = 0000;
 
//The code that randomly selects one of the urls from the list above and causes the redirect
setTimeout(function(){
    window.location = URLlist[Math.floor(Math.random() * URLlist.length)];
}, reDelay);

Where to Place Javascript Multiple Url Redirect

You modify the list of urls to as few as two to as many urls as you wish. Make sure each url is on a separate line with a comma after each url except the last one in the list.

After changing the urls in the list to your needs, copy and paste all of the code from the textbox above and place it anywhere in the web page between the <head> and </head> of the web page. If you use Wordpress you will want to install a plug in that allows you to insert javascript in individual posts. (header.php) of a single post.

PHP Multiple Url Redirection

php
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
<?php
// The list of urls you wish to redirect. One per line. <br>
$destlink1 = 'http://AnyURLorAffiliateLinkHere.com/example1';
$destlink2 = 'http://AnyURLorAffiliateLinkHere.com/example2';
$destlink3 = 'http://AnyURLorAffiliateLinkHere.com/example3';
$destlink4 = 'http://AnyURLorAffiliateLinkHere.com/example4';
 
$randNum = rand(1 , 4); // Change the second number 4 to the total number of links you have above<br>
 
// Adjust the code below to the total number of links you have.
if ($randNum == 1){header("Location: $destlink1");}
elseif ($randNum == 2){header("Location: $destlink2");}
elseif ($randNum == 3){header("Location: $destlink3");}
else {header("Location: $destlink4");}
exit();?>

Where to Place PHP Multiple Url Redirect

Place the above code at the very top of the web page before anything else, even before the starting <head> tag at the top of the page. This is because the code has calls to the php header function which will fail and raise an error if header code has already been executed by the web server.

Need Help with Javascript or PHP Multiple Url Redirect Code?

If you have unsure about how to implement or use the code for your situation then feel free to contact us and we can help you.

CONTENT RELATED TO MULTIPLE URL REDIRECTION SCRIPTS FOR JAVASCRIPT OR PHP



View Hidden Content On Any Website Bookmarkle

... marklet does is completely strips all css styles from the current web page you are on with a single click. It is css styling with styles such as display:none; and visibility :hidden; which keep things ...

Javascript Scrollintoview Alternative Make Co

... ' ... Of course the Javascript code does this so fast you don't see the swapping happening. Depending upon your level of experience with HTML and Javascript, this may seem quite daunting, but it is re ...

How To Create Javascript Bookmarklet

... raper bookmarklet. You are free to take this content scraper bookmarklet code and use it. Remember your first want to put all the Javascript code on one line. You can then either run it immediately by ...

COMMENTS ON MULTIPLE URL REDIRECTION SCRIPTS FOR JAVASCRIPT OR PHP

Feel free to submit your comment below. Anything that does not contribute and is just spam will automatically be deleted. Questions marked by * are required. Comments are checked by a human to make sure they are not spam/automated and are on topic and related to Multiple URL Redirect Scripts For Javascript Or PHP. 
NAME:
EMAIL:
COMMENT:
HTML OK. Allowable HTML tags include: <p></p>, <i></i>, <b></b>, <em></em>, <strong></strong>, <ul><li></li></ul>, <ol><li></li></ol>
Question ❔
Back to Top