%{HTTP_REFERER} not working

Topics: User Forum
Sep 25, 2006 at 4:10 AM
%{HTTP_REFERER} appears to be not working:

ini:

RewriteCond %{HTTP_REFERER} whatever

log:

Mon Sep 25 12:06:32 2006 - ReplaceServerVariables: VariableName='HTTP_REFERER'...
Mon Sep 25 12:06:32 2006 - ReplaceServerVariables: TestString='%{HTTPREFERER}' out='HTTPREFERER'

using version 1.2.9
Coordinator
Sep 25, 2006 at 10:01 PM
Hmm, I cannot tell just what your log is showing. It looks like the formatting got tweaked a bit? The underscores are missing from the 2nd log line you showed there.

A couple of other comments though:
1.
%{HTTPREFERER} will evaluate to "HTTPREFERER" when there is no referer. This could happen, for example, if the user simply types in your URL in the address bar of a browser. There is no referer in this case.

What do you get if you have a bonafide referred page? For example, in some cases the .css (external stylesheet) will be requested, and the HTTP_REFERER in that case, would be the originally requested page.

Example:

Mon Sep 25 15:00:05 2006 - New Url: '/winisp/'
Mon Sep 25 15:00:05 2006 - ApplyRules (depth=0)
Mon Sep 25 15:00:05 2006 - Rule 1 : 1 matches
Mon Sep 25 15:00:05 2006 - GetServerVariable: cannot find that variable
Mon Sep 25 15:00:05 2006 - ReplaceServerVariables: VariableName='HTTPREFERER' Value='HTTPREFERER'
Mon Sep 25 15:00:05 2006 - ReplaceServerVariables: TestString='%{HTTPREFERER}' out='HTTPREFERER'
Mon Sep 25 15:00:05 2006 - GenerateReplacementString: src='/winisp/','(null)' ReplacePattern='HTTP_REFERER' vec=[[ [ 0, 8] [] ] counts=1,0
Mon Sep 25 15:00:05 2006 - EvaluateCondition: checking 'HTTP_REFERER' against pattern '(www\.blockme\.org)$'
Mon Sep 25 15:00:05 2006 - Cond : -1 (No match)
Mon Sep 25 15:00:05 2006 - Cond : Child is NULL
Mon Sep 25 15:00:05 2006 - EvaluateConditionList: FALSE, Rule does not apply
Mon Sep 25 15:00:05 2006 - ApplyRules: returning 0
Mon Sep 25 15:00:05 2006 - No Rewrite
Mon Sep 25 15:00:05 2006 - HttpFilterProc SFNOTIFYURL_MAP
Mon Sep 25 15:00:05 2006 - HttpFilterProc SFNOTIFYLOG
Mon Sep 25 15:00:05 2006 - HttpFilterProc SFNOTIFYURL_MAP
Mon Sep 25 15:00:05 2006 - HttpFilterProc SFNOTIFYAUTH_COMPLETE
Mon Sep 25 15:00:05 2006 - DoRewrites
Mon Sep 25 15:00:05 2006 - New Url: '/winisp/style/basic.css'
Mon Sep 25 15:00:05 2006 - ApplyRules (depth=0)
Mon Sep 25 15:00:05 2006 - Rule 1 : 1 matches
Mon Sep 25 15:00:05 2006 - ReplaceServerVariables: VariableName='HTTP_REFERER' Value='http://localhost/winisp/'
Mon Sep 25 15:00:05 2006 - ReplaceServerVariables: TestString='%{HTTP_REFERER}' out='http://localhost/winisp/'
Mon Sep 25 15:00:05 2006 - GenerateReplacementString: src='/winisp/style/basic.css','(null)' ReplacePattern='http://localhost/winisp/' vec=[[ [ 0, 23] [] ] counts=1,0
Mon Sep 25 15:00:05 2006 - EvaluateCondition: checking 'http://localhost/winisp/' against pattern '(www\.blockme\.org)$'
Mon Sep 25 15:00:05 2006 - Cond : -1 (No match)
Mon Sep 25 15:00:05 2006 - Cond : Child is NULL
Mon Sep 25 15:00:05 2006 - EvaluateConditionList: FALSE, Rule does not apply
Mon Sep 25 15:00:05 2006 - ApplyRules: returning 0
Mon Sep 25 15:00:05 2006 - No Rewrite




2.
Maybe try v1.2.10g if the v1.2.9 does not work for you.

-Dino
Oct 20, 2006 at 9:22 AM
ok, i sorted this all out, thanks for your help.
my mistake was i was assuming that if HTTP_REFERER was missing, it would present as empty.


i now have a set of rules that block direct image linking, with a list of sites allowed to link:

RewriteRule ^blocked\.png$/ blocked.png I,L
RewriteCond %{HTTPREFERER} ^(?!HTTPREFERER)
RewriteCond %{HTTP_REFERER} ^(?!https?://(?:www\.)nintek\.com\.au/) I
RewriteCond %{HTTP_REFERER} ^(?!https?://203\.0?30\.0?46\.178/)
RewriteCond %{HTTP_REFERER} ^(?!https?://(?:www\.)nindeals\.com\.au/) I
RewriteCond %{HTTP_REFERER} ^(?!https?://203\.0?30\.0?46\.181/)
RewriteRule \.(?:gif|jpg|jpeg|png)$ /blocked.png I,L

Coordinator
Oct 26, 2006 at 11:44 PM
Byron, very helpful,
thanks for sharing.

-Cheeso