Forum Moderators: phranque

Message Too Old, No Replies

Weirdest..htaccess..problem..ever

Redirects works on Mac but not on Windows IE

         

MichaelBluejay

3:56 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



(Many apologies for the cross-post -- I accidentally posted this earlier in the Unix forum when it should have gone here. D'oh!)

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.

gergoe

5:08 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



Put

RewriteCond %{HTTP_REFERER} .

to the top of the RewriteConds to see what happens. ...regardless of the fact that you think it is being passed or not

MichaelBluejay

5:15 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Putting that in there made the splash page not appear at all. I put an asterisk after the period, so I had .*, and then the splash page appeared again, and so did the original problem: The splash page just loads over and over again. :(

jdMorgan

5:19 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTTP_REFERRER is not reliable - especially in cases where you can put the visitor into a loop.

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

gergoe

5:28 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



It did not appeared because the referrer string was empty, therefore your htaccess code always redirected the request initiated from your splash page to the splash page again and again. By puting the dot thing there you ensure that requests with empty referrer string will not end up in a dead loop.

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.

gergoe

5:33 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



...by changing the . to .* you made one step back as the purpose of a single dot was to proceed with the rewriting only if there are one or more characters in the referrer string, but by changing it to .* you say that proceed with the processing whatever (not) is in the referrer string, even if it is completelly empty. So you ended up in a dead loop again

MichaelBluejay

7:50 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Okay, but like I said, if I have the dot by itself, then my splash page never appears at all.

jdMorgan

9:30 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JavaScript does not pass a referrer. Neither do bookmarks.
This won't work.

Jim

MichaelBluejay

6:04 am on Nov 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry it took me so long to follow up, I've been out of town.

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.