Dynamic HTML redirects? Help!! :D

SuperSix

Elite Member
Oct 9, 1999
9,872
2
0
Hello!

I'm down to one persistent error in my website's error logs - and need AOT help! :D

With my first web host, my links in my web store were like this: "/cgi-bin/webc.cgi/st_prod.html?p_prodid=287"

With the newer web host they are "/cgibin/webc.cgi/st_prod.html?p_prodid=287" (Note the missing "-" between the "cgibin"

Some old links are still floating around, and I want to redirect the pages, basically strip out the "-". I've set up a custom 404 page, but I would like the surfers to get to the product(s) they are looking for.

Any way to do this?

Thanks!
 

calpha

Golden Member
Mar 7, 2001
1,287
0
0
Here's the html code for a url sniffer.

There's two buttons that simulate url strings
this is to show you how to use regexps.

2nd....you need to look at the code...i put comments in there to help you change it when you put it on the server.

....all's you need to do is put this script in your default 404 page. You won't be able to test this unless you put it on a server, and have a bad link somewhere you know about b/c referrer is blank sometimes when you type it in manually.

<HTML>
<HEAD></head>
<Script language = "javascript">
function changeURL(o)
{
//var str = document.referrer; use this to get the url instead of the button value
var str=o.value;
var place = new RegExp("cgibin")
var isfound = place.test(str);
//we found the pattern, so instead of the 404, let's set a windows timer

if (isfound)
{
str=str.replace(place,"cgi-bin");
o.value = str;
//set a js timer
//document.write ("The page you are trying to visit has been moved. You are being redirected there now");
//location.href = str;
}
else
{
alert ("Your Entry was fine");
}


}

</script>

<body onload="alert(document.referrer)">


<input type="button" value = "h ttp://myweb.com/cgibin/412.html"]http://myweb.com/cgibin/412.html" onclick = "changeURL(this)">



<input type="button" value = "h ttp://myweb.com/cgi-bin/412.html"]http://myweb.com/cgi-bin/412.html" onclick = "changeURL(this)">

<script>
document.write ("Referrer = " +document.referrer);
</script>
<body>
</body>
</html>
 

calpha

Golden Member
Mar 7, 2001
1,287
0
0
btw...you need to change the structure of changeurl(o) to changeurl() and not pass a parameter.

And then add the <body onload = "changeurl();">

add that to taking out the buttons and crap and it will work.

One note about referrers. You will have to find a link to an invalid product id, and type/paste that in your browser for it to work right. I still haven't figured out the ins and the outs of the document.referrer b/c sometimes when I'd think it would be non-empty, it's stil empty. And I swear to god, sometimes on IE it's empty and on Mozilla it's not.

But....the general idea is there. 404 page looks at the referrer, and if it's contents have a cgibin, replace that w/ cgi-bin and redirect.