Forum Moderators: coopster

Message Too Old, No Replies

Redirecting based on referer from Google images.

Not working when I give a string specification and header redirect.

         

HughMungus

9:28 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have an old website that appears to have a lot of images listed very highly for some choice words on Google images. Right now, if someone clicks on the image, they're redirected via an .htaccess redirect and frame-busting script to my new website's home page.

What I'm trying to do now is add some code to the page they're being redirected to to see if specific strings (image names) are in the referer URL so that I can redirect them to the appropriate page with that image. I know the part of the code that finds the string works but when I add a redirect to it, the redirect process slows to a crawl and if it ever does redirect, the browser shows the contents of my "home" directory (!) I removed the frame-busing script in case that was the problem but I'm having the same problem.

$string = 'foo.jpg';
$refererurl = $_SERVER[HTTP_REFERER];
$position = strpos($refererurl, $string);
if ($position === false)
{
}
else Header("Location: http://www.example.com/foo.jpg");

Update: Now the problem is that the redirect works but if I try to use something like, "?image=foo.jpg" it doesn't work (or, to be more specific in my case,?i=3 which is a reference to an article number in the databse). I'm guessing that there's some problem making a database call or using a variable like that inside a header redirect (?)

TIA

[edited by: coopster at 9:58 pm (utc) on Dec. 22, 2004]
[edit reason] generalized url [/edit]

StupidScript

10:08 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I had a similar problem that was resolved by building the header location string into a variable before invoking the header:

$getstring="foo.jpg";

$locstring="http://www.example.com/index.html?image=".$getstring;

header("Location: $locstring");

Perhaps it will work for you, too ...? :)

HughMungus

11:50 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks but no, that's not working.

HughMungus

2:02 am on Dec 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But...you did give me an idea. Since I'm using a javascript frame breaker anyway and since Google images uses frames, I decided to move the redirect part to the javascript frame breaker script. But if anyone knows the answer to the original question for future reference, I would like to know.

coopster

2:01 pm on Dec 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Doesn't look so much like a PHP issue as it is an Apache Redirect issue (you said you were using an .htaccess file). You may need to post in the Apache Forum [webmasterworld.com] and show your directive.