Forum Topic: referer (w/long url) redirect

Forum: .htaccess Forum : General • Posted by RememberToForget • Updated:

This has been kicking my ass all day.

I can referer redirect, say, baidu.com, but how do I target this, for example:

http://www.reddit.com/r/deduction/comments/16hqiq/help_finding_a_lost_lover_guide/

One thing I tried, and this has worked before, is this:

RewriteCond %{REQUEST_FILENAME} .*
RewriteCond %{HTTP_REFERER} 16hqiq [NC]
RewriteRule .* http://goo.gl/Rf87cH [R=302,L]

Of course, the '16hqiq' is unique enough, but that didn't work.

The thing is, I don't want to redirect all incoming traffic from reddit, but from a thread here and there.

4 Replies to “referer (w/long url) redirect”

Jeff Starr
Posted by Jeff Starr

That should work if you replace HTTP_REFERER with REQUEST_URI. Also the REQUEST_FILENAME directive is not required. And check out this article for help with the different server variables and related blocking techniques.

Posted by RememberToForget •

REQUEST_URI and HTTP_REFERER are interchangeable?

Good to know; thanks.

Jeff Starr
Posted by Jeff Starr

No, they're not interchangeable per se, but as explained in the article linked to in previous reply, they represent server variables. So for each request, there is an IP, referrer, request URI, as well as other information, such as a host, query-string, and so forth. When writing your htaccess rules you can use any server variable that makes sense.

So if you're getting hammered by requests that vary across all variables except the user-agent, well then that's the variable that we want to match against. I hope this makes sense, it's fundamental to what we're doing here.. check that article for a more in-depth view.

Posted by RememberToForget •

It makes sense, and it helps to have things re-explained a few hundred times. :)

I've read your book cover to cover twice, plus most of your posts at least that many times, and frankly I'm a very slow learner due to a deficiency in left-brain processing and a memory problem that is downright hilarious in its profundity.

I'm pretty much a Reagan in his 90's.