Click to See Complete Forum and Search --> : Automatic Redirect


robmartin3
05-26-2003, 10:13 AM
I've just done my first web page for my small business, and have a question. I've got four domain names for my four business lines, all aliased to the same hosting address. I'd like to be able to have four "sub webs" below my index page, without links to each other. I'd like the index page to automatically redirect to the appropriate subweb based upon the URL the user types in. That is, if they type in www.twowheelradio.com, they go to the two wheel radio home page, if they type www.robmartin.tv, they go to a different set of pages, which are all in the same web, but which have no links to one another, etc. Is there a way to interpret which URL the user has typed in and then redirect to the appropriate subweb based on that value?

Sorry if this is a basic question, and thanks for any help.

Rob

Jona
05-26-2003, 10:43 AM
You can use one of the following server side languages:

ASP (http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=9)
CGI/Perl (http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=4)
PHP (http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=16) (What I use most often.)

If you want to know how to do it in PHP, just ask--or post in the PHP forum.

robmartin3
05-26-2003, 11:11 AM
Thanks, and sorry, my question was a little general. I'm a rank amateur, and don't even know what PHP is... I was more asking what it is I'd query/look at to figure out what the user typed in, and then how I'd do the redirect. I'm guessing I have one index page with one if statement on it (sorry, my COBOL is showing) that says something like

IF the URL was www.robmartin.tv GOTO www.robmartin.tv/rmtvhome.htm
OR
IF the URL was www.commedy.net GOTO www.commedy.net/cnhome.htm
OR...
ELSE GOTO www.twowheelradio.com/twrhome.htm

I just don't know what to look at to figure out what they typed in or how exactly to send to the other page without the user seeing a screen telling them to click, cause I don't want the users of one subweb to know the others even exist...

I hope that makes sense. I can post in the PHP forum if that makes more sense.

Rob

Jona
05-26-2003, 11:30 AM
If you're willing to do it in php, make your index file index.php, and use this (make sure it's before even the doctype in your document, or else you'll get an error):


$ref = $_SERVER['HTTP_REFERER'];
if($ref=="http://robmartin.tv/" || $ref=="http://www.robmartin.tv/"){
header("Location: http://www.robmatrin.tv/rmtvhome.htm");
else if($ref=="http://commedy.net/" || $ref=="http://www.commedy.net/"){
header("Location: http://www.commedy.net/cnhome.htm");
} else {
header("Location: http://www.twowheelradio.com/twrhome.htm");
}

robmartin3
05-26-2003, 11:59 AM
That is awesome, thank you so much. Not to appear ungrateful, but now figuring out a little more at a time, I am using FrontPage, which doesn't seem to support PHP, at least I can't get it to take a .PHP file and recognize it in navigation. It does seem to support ASP, cause it says I can save a file as an .ASP type. Would this code work in ASP? Or do you know any tricks to get Frontpage to like the PHP stuff?

Thanks again!
Rob

Jona
05-26-2003, 12:04 PM
Oh, you're using an editor. I use Notepad for all of my stuff. I guess I forgot.

Actually, I don't have FrontPage, so I don't know how to use it, but... Microsoft made ASP so that's why it recognizes .asp files and not .php files. Now then, I think there is a code-view in FrontPage, right? Well, what you can do is put the PHP code I gave you in the *very* top of the document. Before any other code. Then, export the file to .html. Then, go find the file in whatever folder you saved it in, and rename it with .php instead of .html. Or, right-click it and open it with Notepad, and click File-> Save As... And type in "index.php" (with the quotes). And also, I'd suggest that you select, "Save As Type: All Files (*)" That should do it. Then upload it to your server, and move the index.htm file out and replace it with the index.php file. Then tell me if it works because I actually haven't even tried that code. lol