Forum Moderators: phranque

Message Too Old, No Replies

Using SetEnvIfNoCase, Will This Work?

Wanting to block a referer, but last character in domain could be different

         

MickeyRoush

9:04 pm on Aug 23, 2011 (gmt 0)

10+ Year Member



Say I want to block example.com using SetEnvIfNoCase.

SetEnvIfNoCase Referer ^(www\.)?example\.com ban
deny from env=ban

Where example.com could be that alone or with any other character after example:

example.com
example2.com
example3.com
examplea.com
examplez.com

and so on.

Would this work?

SetEnvIfNoCase Referer ^(www\.)?example(.{1,})?\.com ban
deny from env=ban

Or maybe something like this:

SetEnvIfNoCase Referer ^(www\.)?example([a-z0-9]{1,})?\.com ban
deny from env=ban

wilderness

9:53 pm on Aug 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



SetEnvIfNoCase Referer [google.com]

lucy24

10:20 pm on Aug 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Or maybe something like this ...

Either way would work. But the form {1,} is just a verbose way of saying + at a cost of three extra bytes. And it's overkill if what you really mean is {,1} ("no more than one") abbreviated as ? alone. Never let the server go scooping up multiple characters if you only need one.

Don't use . alone, because then the regex may have to backtrack and say "whoops, I wasn't supposed to include literal periods".

If your server recognizes the \w locution, use it:

example\w?\.com

Otherwise

example[^.]?\.com

MickeyRoush

10:52 pm on Aug 23, 2011 (gmt 0)

10+ Year Member



@ lucy24

This is what I was looking for:
example[^.]?\.com

Thanks!