Forum Moderators: phranque
So I decided that whenever anyone enters any page of my site from anywhere outside my site, I want to show them a splash page for about ten seconds and then redirect them to whatever page they intended to get in the first place.
Yeah, yeah, I know that splash pages are bad. This is a temporary change, and I have very good reason for doing this, trust me.
Anyway, everything works fine on my Mac. But in Windows IE the same page keeps loading over and over again.
Here's my .htaccess file:
RewriteCond %{HTTP_REFERER}!mydomain\.com [NC]
RewriteCond %{REQUEST_URI}!(redirect¦picturename)
RewriteCond %{HTTP_USER_AGENT}!(google¦msn¦slurp¦yahoo)
RewriteRule (.*) [mydomain.com...] [R,L]
And redirect.cgi is basically this:
print qq[
Content-type: text/html\n\n
<HTML><HEAD>
( META-REFRESH or JavaScript Redirect in 10 seconds to [domain.com...] )
</HEAD><BODY>
<A href="http://domain.com/$ARGV[0]"><IMG SRC="picturename.jpg"></A>
</BODY></HTML>
];
What should happen is that if a user clicks a link to [mydomain.com...] they get redirected to a splash page that lets them click to continue to <mydomain.com/subpage>, and if they don't click then they get redirected automatically.
And it works fine...in Safari. And it works fine in Windows if the user clicks the picture to proceed. But if either the META-REFRESH or JavaScript handles the redirection, I hear the "click" but then the splash page reappears. If I view the source I see that the inserted pagename in the <HEAD> is correct, and it's obviously correct because Safari can redirect to it.
I printed out $ENV{'HTTP_REFERER'} from Perl onto my splash page and it shows my domain and full path of the redirect script, so I know the referer is getting passed.
What the heck is going on here?! Thanks very much for any help you can provide.
Use cookies to solve this problem. It's a common thing to look through your own browser's cookies and find lots of them named "Visited" and "Seen" and such, indicating that they were used for a similar purpose to yours.
Jim
If it is not what you need, then you need to forgot this referrer thing as the presence of it depends on the client browser; maybe it sends one, maybe not.
jdMorgan said that JavaScript doesn't pass the referrer. I found that that's not quite correct, but that did set me on the path to solving the problem. I tested and found that there's quite a disparity between Mac Safari and IE6/Windows as to when the referrer gets passed. I made a file called <index.html> and linked it to <test.cgi> which outputs the referer string. Here's what I discovered:
WAS THE REFERER PASSED?
----------------------------------------------
Safari IE6.028 Action
------ ------- ------------------------
yes yes Click from <index.html> to <test.cgi>
NO yes Once there, click in the address bar & press Enter
NO yes Click from <index.html> to <test.cgi>, retype the <test.cgi> url from scratch
NO NO Load Google.com, type <test.cgi> into the address bar and press Enter
yes yes Click from <index.html> to <test.cgi>, click Refresh button
yes NO Meta-Refresh from <index.html> to <test.cgi>
yes NO JavaScript redirect with set.timeout and window.href="..."
As gergoe suggested, the solution to get <.htaccess> to act on blank referers is to use this line:
RewriteCond %{HTTP_REFERER} . Earlier when I tried that, it no longer even went to my splash screen at all. But now I see what the problem was -- I was retyping the URL into IE, which sendt my domain as the referer! Once I set up a link from another domain and clicked from it over to my main domain it worked fine. So, it was working all along (at least after the suggestion of adding the line to catch a blank referer), I just didn't realize it.
Thanks everyone for your help. I hope this table about referer passing is useful to someone, somewhere.