4

A web-site(wwww.fake-web-site.com) redirects its links to my web-site(www.real-web-site.com). Only the first page is different.

I wrote a code to redirect all people which come from the fake site to google.com.

if (strpos($_SERVER['HTTP_REFERER'],'fake-web-site.com') !== false)
  header('Location: http://www.google.com/search?q=real-web-site.com');

It works on Chrome browser, if someone opens the fake web-site and clicks on those links which are linked to my web-site, it will be redirected to google.com. After that he can open my site from google.com.

In Firefox, if someone opens the fake web-site and clicks on those links which are linked to my web-site, it will be redirected to google.com after that, if he clicks on real-web-site.com in google.com, he redirects again to the google.com!

I think it's related to Firefox cache mechanism. Can someone give a suggestion?

masoud
  • 55,379
  • 16
  • 141
  • 208
  • This sounds a bit confusing. What are you trying to achieve? Do you want to atifically generate search requests looking for your page to fake popularity? – Mario Jul 29 '13 at 07:10
  • may be firefox caching header –  Jul 29 '13 at 07:11
  • @Mario: No, the fake page is attracting my customers, and its domain rank is better than me in search engines. I don't want those links to my web-site. If someone wants to visit the real site, he shouldn't find it from the fake site. – masoud Jul 29 '13 at 07:19
  • try to dump $_SERVER lets see what happen – Shushant Jul 29 '13 at 07:24

1 Answers1

0

Browsers cache redirects. Depending on the HTTP response status:

If the status is 301 Moved Permanently then the browser should and will (probably) cache it.

If the status is 302 Found then the browser shouldn't and won't cache it.

Anything else is left to the browser to decide. From your code it seems like you're just responding with 200 OK.

You can set a response header in PHP by doing e.g.:

header("HTTP/1.0 302 Found");

This has to be done before any other body or header output - unless you're using output buffering.

thwd
  • 23,956
  • 8
  • 74
  • 108
  • Interesting, let me try it. – masoud Aug 05 '13 at 17:07
  • Imho PHP is using 302 as default when using Location. To make sure the response is _really_ not being cached, explicitly forbid it in the HTTP header (see http://stackoverflow.com/a/2068407/413531) – Hirnhamster Aug 23 '14 at 21:52