Forum Moderators: phranque

Message Too Old, No Replies

problems with http_referer redirect

         

KonnyQ

10:35 am on Mar 26, 2003 (gmt 0)

10+ Year Member



Hi Guys!

As many others in these forums I have to come out with a htaccess question too. Hope you still can hear it and maybe give me a little help. I've read so much in the mod-rewrite tutorials but still can't figure. ;)

Problem:
We have to block links from a "bad domain" and we want to send the people klicking on these links to a certain banned-page on our domain saying "you're using the wrong way blabla".

This is our htaccess file with various rewrite rules which worked fine so far, exept of the last rule which should do the mentioned redirect. What happens is, klicking on the links on the banned domain results in a 302 saying "found, page moved to 'banned.htm' ".

Fine, I'd much rather have a propper redirect for one thing and the other problem is that this rule fills up our logs with endless loops loading the banned.htm.

Any ideas would be more than nice because this bad domain is burning under my nails! ;)

--

errorDocument 404 /errors/404.html
errorDocument 403 /errors/403.html

<Files .htaccess>
deny from all
</Files>

<Limit GET POST>
order allow,deny
allow from all
deny from #several ip-addresses
</Limit>

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} almaden [OR]
RewriteCond %{HTTP_USER_AGENT} AcontBot [NC,OR]

..

RewriteCond %{HTTP_USER_AGENT} Widow [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Xaldon
RewriteRule .* - [F]

RewriteEngine On
RewriteCond %{http_REFERER} badguys\.com
RewriteRule /* [mydomain.com...] [R,L]

--

thanks in advance!

Konny

Birdman

12:18 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I'm not an expert but noticed a couple thing that don't look right.

1) You only need the first "RewriteEngine [httpd.apache.org] On" line.

2) You need a $ at the end of the first part of the RewriteRule [httpd.apache.org].

RewriteRule [httpd.apache.org] /*$ ht*p://www.mydomain.com/banned.htm [R,L]

andreasfriedrich

12:34 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your /* will match anything since it requires sero or more slashes to match.

To avoid endless loops you need to check whether the REQUEST_URI is /banned.html.

RewriteCond [httpd.apache.org] %{REQUEST_URI}__SPACE__!^/banned.html$

Andreas

KonnyQ

12:36 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



Hello Birdmann,

thanks for your reply! I must be stupid, never thought about the double "RewriteEndine ON". ;)

I also tried using the $, didn't work. I'll try it again with the changes you mentioned and post the result ..

Thank you again sofar!

KonnyQ

12:41 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



Hi Andreas, so I just have to add this line after the baddomain-string?

like:

RewriteCond %{http_REFERER} badguys\.com
RewriteCond %{REQUEST_URI}__SPACE__!^/banned.html$
RewriteRule ..

?

andreasfriedrich

12:43 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes and you need to replace __SPACE__ with a space character :).

Andreas

KonnyQ

12:47 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



good to know, thanks andreas! ;)

KonnyQ

12:57 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



@andreas

Can you explain this a bit more:

"Your /* will match anything since it requires sero or more slashes to match"

I want to make sure that the whole domain is blocked, because the links are sitting on pages in various directories.

"RewriteRule /*$" would be fine than?

andreasfriedrich

1:17 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




>>Can you explain this a bit more:

A match everything RE is usually written as .* which tells the RE engine to match sero or more of any character. At the end of the day this is really the same as your /* rule. In fact you could write such a rule as (when in the course of human events it becomes necessary for one people to dissolve the political bands which have connected it with another a decent respect toward the opinions of mankind requires them to declare the causes which impell them to separation)* or a bit simpler (MmmBop)*.

But usually these rules indicate that the author was not aware of the fact that they would indeed match anything. Most of the time they meant to write (MmmBop)+ which would match one or more occurances of MmmBop.

>>"RewriteRule [httpd.apache.org] /*$" would be fine than?

It would be for the reasons given above. It will simply match sero or more slashes at the end of the string. Since there´s always at least nothing at the end of the string this will make sure that the whole domain is blocked. A pattern like .* would be a bit clearer though.

If the slash indicates that you were trying to match a slash followed by some other characters then that RE would have to be written as /.*. In directory context this would not work though, since mod_rewrite [httpd.apache.org] strips off the directory prefix of the URL to allow for local matching at each directory level. If you used this RE in httpd.conf it would work since no stripping is done.

Andreas

KonnyQ

2:01 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



puh, thanks andreas for the nice explanation! ;)

unfortunately my htaccess-mess still won't work. I'll post it again because maybe there's a bug in the mix of the various parts, maybe a line break too much or what ever.

Problem: The following script results in a 500 Error. Hm ..

--

errorDocument 404 /errors/404.html
errorDocument 403 /errors/403.html

<Files .htaccess>
deny from all
</Files>

<Limit GET POST>
order allow,deny
allow from all
deny from # blocked ip-addresses
</Limit>

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} almaden [OR]
RewriteCond %{HTTP_USER_AGENT} AcontBot [NC,OR]
..

RewriteCond %{HTTP_USER_AGENT} Widow [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Xaldon
RewriteRule .* - [F,L]

RewriteCond %{HTTP_REFERER} badguys\.com [NC]
RewriteCond %{REQUEST_URI}!^/banned.htm$
RewriteRule .* ht*p://www.mydomain.com/banned.htm [R,L]

--

Any idea what's wrong? I don't know but I want to know and sooner or later I know I will know .. ;)

Konny

andreasfriedrich

2:24 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have access to the error logs?

What´s the error message?

Andreas

KonnyQ

2:32 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



I can't access the log before tomorrow. it's copied daily.

but the browser "says" > Internal Server Error 500 <

KonnyQ

2:36 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



@ andreas, sorry, mistake, I mentioned the access log, the error logs I can't access at all ..

andreasfriedrich

2:45 pm on Mar 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I pasted your code into a local .htaccess file, added the missing space before the! and got no errors.

Andreas

KonnyQ

2:49 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



andreas, you're a nice guy ;), I'll try it again, maybe I missed something ..

KonnyQ

3:15 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



there's no error anymore, but the banning won't work either. nothing happens, mydomain shows up as it should but the links from badgyus still work.

KonnyQ

5:26 pm on Mar 26, 2003 (gmt 0)

10+ Year Member



Once again, hi andreas and anyone else:

My htaccess finally works, all I did was taking out "\.com” at the end of the first line. I don't know why and what but it seems to work now. If anyone knows why, feel free to tell me. ;))

--

RewriteCond %{HTTP_REFERER} badguys [NC]
RewriteCond %{REQUEST_URI}!^/banned.htm$
RewriteRule .* ht*p://www.mydomain.com/banned.htm [R,L]

--

We will see what the logs say tomorrow, I'll get back here, it's a nice place! ;)

Thanks for the help!

Konny