Forum Moderators: phranque
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
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]
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
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
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
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