PDA

View Full Version : .htaccess referer blocking


gsnedders
07-09-2005, 01:54 PM
OK, I need some help, as many of you know, I really don't know all too much about .htaccess and related things.

What I need to do is redirect any domain containing "generic-online.info" (including subdomains) to /spam.html

Span
07-10-2005, 12:12 PM
Referrer spammers are not humans but robots. You can tell a robot you don't like your logs being spammed, but they really don't care.

You can redirect them like this to your spam.html:

RewriteEngine On
RewriteCond %{HTTP_REFERER} generic-online\.info [NC]
RewriteRule .* /spam.html [L]

But if I were you I would give them a simple 403:

RewriteEngine On
RewriteCond %{HTTP_REFERER} generic-online\.info [NC]
RewriteRule .* - [F]

gsnedders
07-10-2005, 01:37 PM
I know that there robots, I just want them not to access the site.

Would the following block any sub domains? RewriteCond %{HTTP_REFERER} [\w\-_.].generic-online\.info [NC]

Span
07-10-2005, 06:53 PM
Hi,

RewriteCond %{HTTP_REFERER} generic-online\.info [NC]

..since that condition is not anchored (^ is start anchor, $ is end achor), it will match every referrer with that domain in it. With or without www. or any other subdomain in front of it or directories and/or page names following it.

gsnedders
07-10-2005, 08:27 PM
Ah. RegEx really isn't a strong point of mine :)

Span
07-10-2005, 11:56 PM
Well, looking at your age, by the time you're 16 I'm gonna ask you how to rewrite URLs for a 15.000 pages site.

If you want to add more conditions, use the OR flag at the end of all lines but the last.

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain\.tld [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain\.tld/folder/page\.html$ [NC,OR]
RewriteCond %{HTTP_REFERER} domain1\.tld [NC,OR]
RewriteCond %{HTTP_REFERER} domain2\.tld [NC,OR]
RewriteCond %{HTTP_REFERER} really-bad [NC]
RewriteRule .* - [F]

gsnedders
07-11-2005, 12:01 AM
Well, any good links to a tutorial?

Only the one condition for now :)