Web Page Help

Ok, I’ve bashed my head for the last few hours.

I’m trying make a simple redirect script for a web page

If your IP address begins with 207.206
goto http://this site.com
else
goto http://that.site.com

I don’t care how it’s occomplished (php, server config, java, javascript,etc)

It’s on a apache 1.3.19 server that I have complete control over. I’ve spent the last couple of hours trying to do it with javascript, and everything I’ve come up with is Netscape only. Arrg!

Can anyone help?

Please?

heres some php



<?php

if ( strstr($REMOTE_ADDR, '207.206') ) {
  header ("Location: http://this.site.com");
  exit;
} else {
  header ("Location: http://that.site.com");
  exit;
}

?>


I didn’t test it out.
Let me know if it doesnt work, and I’ll fix it.

Um, how’s this work.

I’m assuming the file has to be renamed from index.html to index.php?

Never dealt with PHP before?

*Originally posted by Brandon Martus *
**heres some php



<?php

if ( strstr($REMOTE_ADDR, '207.206') ) {
  header ("Location: http://this.site.com");
  exit;
} else {
  header ("Location: http://that.site.com");
  exit;
}

?>

 


I didn't test it out.
Let me know if it doesnt work, and I'll fix it. **

Ok, I’ve enabled SSI on the server, turned on XBitHack, and made the page executable.

It was halfway working, but now it’s not.

by halfway I mean this.
I should have been clearer in my example.

if 207.206
https://netreg.bridgew.edu/indexresnet.html
else
https://netreg.bridgew.edu/indexall.html

I had those two locations in there, and when it was partway working, it would redirect to the httpS, but it wouldn’t pick up the document.

Do you have mod_rewrite setup on your Apache server?

Ok, I called in one of the programming guru’s at work, and in trying to explain it to him, I hit apon the solution.

The solution that I’ve discovered is a combination of Javascript and SSI includes.


<noscript><meta http-equiv="refresh" content="2; URL=indexresnet.html"></noscript>
<script language="JavaScript">
<!--
var resnetsTargetURL = "https://netreg.bridgew.edu/indexresnet.html";
var allsTargetURL = "https://netreg.bridgew.edu/indexall.html";


function doRedirect()
{
var ip = "REMOTE_ADDR";
if (ip.indexOf("192.168") >= -1)  
        setTimeout( "window.location.href = resnetsTargetURL", 2*1000 );
else
        setTimeout( "window.location.href = allsTargetURL", 2*1000 );
}
//-->
</script>

<script language="JavaScript1.1">
<!--
function doRedirect()
{
var ip = "REMOTE_ADDR";

if (ip.indexOf("192.168") >= -1)  
   window.location.replace( resnetsTargetURL );
else
   window.location.replace( allsTargetURL );
}

doRedirect();

//-->
</script>

of course the <body onload=“doRedirect()”> tag is in there too.

Thanks for all your suggestions, you guys at least got me started on the right road.

Ok, just a small minor update. The previous script I posted don’t work.

I did a google search on SSI redirects

Came up with this script. Keep in mind this is the entire webpage.


<!--#if expr="${REMOTE_ADDR} = /192.168.10/" --> 
<!--#include file="indexresnet.html" --> 
<!--#else --> 
<!--#include file="indexall.html" --> 
<!--#endif --> 

Kinda neat, eh?

The pages I want displayed are completely contained in the .html files.

Too bad no one had mentioned server side includes to me before. (they’ve been suppored since both browsers verion 2.0)

oh yea :stuck_out_tongue:

i mainly use SSI for

including files
<!–#include virtual="/file/to/include/here.html"–>

and executing cgi’s
<!–#exec cgi="/cgi/date.pl"–>

forgot about the scripting capabilities.

You can use Flash 5 to re-direct to any file. It is simple and most people have the plug-in for it.