block spam url with 404

New to mod_rewrite? This is a good place to start.

block spam url with 404

Postby mazenovi » Thu Sep 10, 2009 12:04 am

Hello everybody,

I try to get work some rules to block spam url as found with a little googling (here for example: http://diveintomark.org/archives/2003/0 ... mbots_ban_ ... go_to_hell)

RewriteCond %{HTTP_REFERER} badurl.fr [NC]
RewriteRule .* / - [F]

For my case, I would like to send a 404 code (for search engine) rather than a 403, and redirect the 404 code on my home page (to not disturb the users).

ErrorDocument 404 /
RewriteCond %{HTTP_REFERER} badurl.fr [NC]
RewriteRule .* /fake.html [L]

The last line doesn't work. if the referer's condition is false it's ok, but if referer contains badurl.fr I have an error 500 Internal Server Error.

RewriteRule .* /fake.html [L,R=404]
Is not correct because R is in 300-400 range, and I didn't find any equivalent flag as F for 404

All suggestions will be appreciate

Thanks

N.B: fake.html doesn't exist
mazenovi
 
Posts: 3
Joined: Wed Sep 09, 2009 11:55 pm

Postby richardk » Thu Sep 10, 2009 7:39 am

The last line doesn't work. if the referer's condition is false it's ok, but if referer contains badurl.fr I have an error 500 Internal Server Error.

The rule matches the request to /fake.html and loops.
Code: Select all
ErrorDocument 404 /
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_REFERER} badurl\.fr [NC]
RewriteRule .* /fake.html [L]


Is not correct because R is in 300-400 range, and I didn't find any equivalent flag as F for 404

There is the G flag (410 Gone)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_REFERER} badurl\.fr [NC]
RewriteRule .* - [G,L]


For my case, I would like to send a 404 code (for search engine) rather than a 403, and redirect the 404 code on my home page (to not disturb the users).

It doesn't sound like it's going to work any better, you'd be telling search engines your whole site does not exist. But only if they came from badurl.fr and only if they send the Referer header anyway.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mazenovi » Thu Sep 10, 2009 8:21 am

Your first proposition is just what I was looking for ...
Thanks a lot
mazenovi
 
Posts: 3
Joined: Wed Sep 09, 2009 11:55 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 28 guests

cron