Redirect a page according to the reference URL via JavaScript


How can I, by using JavaScript, redirect a page based on document.referrer?    <-- referer                 <-- new url

This is what I have tried:

<script type="text/javascript" charset="utf-8">
   if (document.referrer == '' ||
       document.referrer.indexOf('') != 1) {

var ref=document.referrer;
if (ref.indexOf('')>0){

The above code gets the referrer. It checks whether the old site is in use. If so, it strips the beginning and redirects to the new site. The code should be self-explanatory.

The code works if your old site has urls like:

And the new site has the same set of files but a different path, e.g.: