Forum Moderators: phranque
RewriteCond %{THE_REQUEST} HTTP/1\.0$
RewriteCond %{REMOTE_ADDR} !^1\.2[34]\.
RewriteCond %{REMOTE_ADDR} !^1\.234\.12[01]\.
RewriteRule - [F]
(IPs are examples only) [edited by: phranque at 11:47 pm (utc) on Jun 25, 2018]
[edit reason] edited errata in code snippet [/edit]
only by old bots nowadaysEvery time I think I've got a complete (and very short) list, i find another. Considering only the ones that ask for robots.txt or show similar pretensions to robotitude:
And your RewriteRule directive is incomplete, it’s missing a pattern (first argument).
RewriteRule ^ - [F] RewriteRule - [F] [edited by: phranque at 12:09 am (utc) on Jun 26, 2018]
without the [OR] it means you're excluding HTTP/1.0 except for those two IP patterns.Yes, that’s the idea--except, of course, that in real life there would be more exclusions. It translates as “block any requests that use HTTP/1.0 AND don't come from {nice neighborhood #1} AND don’t come from {nice neighborhood #2} AND don’t come from {nice neighborhood #3} AND aren’t named {nice robot #1} AND aren’t named {nice robot #2} AND ” ... et cetera.
RewriteCond %{REMOTE_ADDR} !^1\.2\.3
RewriteCond %{REMOTE_ADDR} !^4\.5\.6
or whether you instead choose to say RewriteCond %{REMOTE_ADDR} !^(1\.2\.3|4\.5\.6)
since shaving picoseconds off processing time isn’t the only consideration.
RewriteCond %{THE_REQUEST} HTTP/1\.0$
RewriteCond %{REMOTE_ADDR} !^1\.2[34]\.
RewriteCond %{REMOTE_ADDR} !^1\.234\.12[01]\.
RewriteCond %{HTTP_USER_AGENT} !(example1|example2|example3)
RewriteRule - [F]
[edited by: phranque at 11:48 pm (utc) on Jun 25, 2018]
[edit reason] cleanup [/edit]
RewriteRule - [F]
you can leave the Pattern unspecified
while i've seen the second usage often i haven't found it documented by apache.
RewriteRule - [F]andRewriteRule ^ - [F]and as expected, they perform exactly the same. RewriteRule !^(ads\.txt|custom403\.html|dnt-policy\.txt|robots\.txt)$ - [F] Some examples of allowed filesWell, if we’re going into detail...
RewriteRule \.txt - [L]
rather than go through the whole list of permitted .txt files. RewriteRule - [F]
do not throw a 500-class error. On my site (Apache 2.2) they are simply ignored: the rule is not executed, and conditions--if any--are not evaluated. I would not consider that to be “performing exactly the same” as a syntactically correct RewriteRule ^ - [F]
or RewriteRule . - [F]
...should be listed in order of likeliest-to-succeedWhile I agree in theory, I've never concerned myself with what amounts to trivial distinction in today's realm of Broadband speeds, SSD and HTTP/2 and how many daily requests do you really get coming in on HTTP/1.0?
On my site (Apache 2.2) they are simply ignored...Since I don't know exactly what/how you tested, I can't really comment. But if that's the case, then certainly do use:
RewriteRule ^ - [F]I'm not really advocating leaving out the anchor, most all of my rules have it. It's just not always necessary in my experience. RewriteRule - [F]
On my site (Apache 2.2) they are simply ignored...
But if it matches it will internally rewrite the requestY'know, I did wonder if that's what was really going on, but at the time couldn't think how to test it: the target - hyphen is read as the pattern, and then the flag [F] is read as the target, with--as you observe--no actual [L] flag.
[Tue Jun 26 11:22:43 2018] [error] [client my-own-IP] File does not exist: /physical-file-path/example.com/[F]I’d actually forgotten that if the target doesn’t start with either http:// or / slash, then it defaults to the current hostname. Then again, it would not have occurred to me to put [ literal brackets ] in an URL. Does any site use them? In paths, I mean; I’ve definitely seen brackets in query strings.