if(fromhere) then(gothere) - can it be done?

They have: 4 posts

Joined: Aug 2000

Greetings,

My apologies if this is the simplest thing in the world - my ISP says it can be done with CGI scripting (but won't tell me how). I looked *all day* yesterday and could not find anything about *how* one might accomplish it.

(NOTE: These are URLs I just made up - don't bother clicking on them.)

What I have are several URLS, like http://www.mysite.com, http://www.mywork.com, and http://www.myhobbies.com (just as examples).

One has "web hosting", the others are just "domain hosting". Currently I have them set up (via the ISP's "Control Panel") so that if someone attempts to visit the two that don't have web space, they get dumped into the one where I actually have a web site. That works. So far so good.

What I want to do when a user arrives at my site is A) Figure out which of my other URLs sent them to my site, and B) Redirect them to the appropriate page - like this:

if (user came from [url]http://www.mywork.com)[/url]
then (send them to [url]http://www.mysite.com/work/)[/url]
if (user came from [url]http://www.myhobbies.com)[/url]
then (send them to [url]http://www.mysite.com/hobbies/)[/url]
else (leave them here at [url]http://www.mysite.com)[/url]

It seems like it couldn't be *that* difficult. Can anyone tell me if it's possible, and where I might find an example? And while were at it, any good book recommendations for learning more about this stuff?

Thank you!
Linda

They have: 10 posts

Joined: May 2000

It would probably be easier to do using JavaScript on your index page using the following syntax at the top of the page after the tag:

<script>
<!--
if (document.referrer == "http://www.mywork.com")
   {location = "http://www.mysite.com/work/";};
if (document.referrer == "http://www.myhobbies.com")
   {location = "http://www.mysite.com/hobbies/";};
-->
&lt;/script&gt;
'

Regards,
Jonathan Michaelson

Way to the Web Ltd
Commercial CGI Scripting
http://www.waytotheweb.com

They have: 10 posts

Joined: May 2000

If you wanted to do something like this in perl CGI (though it's not really practical for this specific purpose) you'd use something like the following in an index.cgi script at the top of your web site:

[code]
#!/usr/bin/perl
if (%ENV{HTTP_REFERER} eq "http://http://www.mywork.com")
{print "location: http://www.mysite.com/work/\n\n";}
elsif (%ENV{HTTP_REFERER}) eq "http://http://www.myhobbies.com")
{print "location: http://www.mysite.com/hobbies/\n\n";}
else {print "location: http://www.mysite.com/index.htm\n\n"}

Regards,
Jonathan Michaelson

Way to the Web Ltd
Commercial CGI Scripting
http://www.waytotheweb.com

They have: 4 posts

Joined: Aug 2000

I can't wait to try it. Thank you so much. Smiling
Linda

They have: 60 posts

Joined: Aug 2000

I have Domain Redirector 1.1 CGI script (freeware) from scriptsolutions.com

If anyone wants to get it, mail to [email protected], I will send it to you.
Or if there is a request to post the code on this board (not very long, about 1 page!), I'll do it!

http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
http://www.ad-rotator.com/ - Free ad rotating system for small websites - Stop Ctrl-P/Ctrl-C the ad code!

------
Son

They have: 193 posts

Joined: Feb 2000

Linda, welcome to TWF! Smiling

Make sure to post if you have any more problems.

Also, for a book recommendation, anything published by O'reilly would be great. I think the book "Learning Perl Programming" (or something like that) would be great for the begginer. Another thing to note is that the above suggested book (if I'm thinking about the right one) was written by the creater of PERL, Larry Wall.

Richard
richjb::413

[email protected]

Everyone here has a website. It's just that not all are worth posting (Mine! Smiling).

They have: 4 posts

Joined: Aug 2000

Son/123Finder's solution worked like a charm - easy to use, worked the first time - once I figured out that I needed to hit Refresh (duh!)

I'm thrilled. I've been putting up with this not being right forever. Now http://www.scritchies.com goes to someplace where I can put my new horse-related site. Yeehaaa.

Thanks to you all, for the suggestions and book recommendation. Smiling Have a great weekend.

Linda

They have: 60 posts

Joined: Aug 2000

I'm using the Black Perl Book, not bad at all!
But the best book I've found when got started with CGI scripting is (still now) CGI101 (www.cgi101.com)

http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
http://www.ad-rotator.com/ - Free ad rotating system for small websites - Stop Ctrl-P/Ctrl-C the ad code!

------
Son

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

would you be able to do something like this with .htaccess?

I know you can for file redirection, but can you put HTTP_REFERER logic in there?

They have: 10 posts

Joined: May 2000

I think you're going to have to do something with Rewrite rules in your conf files (I'm not sure if these work in .htaccess files). You can do what Apache calls Referer Deflection (at the bottom of the following doc):
http://www.apache.org/docs/misc/rewriteguide.html

Regards,
Jonathan Michaelson

Way to the Web Ltd
Commercial CGI Scripting
http://www.waytotheweb.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.