Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Condensing Rewrites

     
6:30 pm on Apr 19, 2015 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 1, 2012
posts: 86
votes: 0


I am seeking to condense these UA blocks:

RewriteCond %{HTTP_USER_AGENT} ^ImageMobile [OR]
RewriteCond %{HTTP_USER_AGENT} ^ImagePro [OR]
RewriteCond %{HTTP_USER_AGENT} ^ImageSearcher [OR]

to this:

RewriteCond %{HTTP_USER_AGENT} =Image[Mobile|Pro|Searcher] [OR]

without blocking this:

Googlebot-Image/1.0

Am I on the right track?
7:44 pm on Apr 19, 2015 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4558
votes: 363


The ^ at the beginning isn't going to do the job unless the actual UA begins with Image Mobile. I think you might be looking for
(ImageMobile|ImagePro|ImageSearcher)
without the ^ before it. That would mean "UA contains".

IF that is the only line, you don't need
[OR]
(which means "or").

IF these UAs sometime vary their case as in "imagepro" rather than "ImagePro" you would need to add
 [NC]
(which means "No Case" or "Case insensitive" and adds a little bit of extra work for the server) where the
[OR]
is now.

IF
there are multiple lines of UAs and their case varies, then you need
[NC,OR]
7:54 pm on Apr 19, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15934
votes: 889


RewriteCond %{HTTP_USER_AGENT} ^ImageMobile [OR]
RewriteCond %{HTTP_USER_AGENT} ^ImagePro [OR]
RewriteCond %{HTTP_USER_AGENT} ^ImageSearcher [OR]

to this:

RewriteCond %{HTTP_USER_AGENT} =Image[Mobile|Pro|Searcher]

Er... You're trying to compress one set of RewriteConds that will not work, to a different set of RewriteConds that will not work?

The first version will always fail because you've got an opening anchor ^ meaning "UA must begin with this text". The second version will fail for two reasons: One, because it begins with = meaning "the following stuff is lexically equal to this literal string" and, two, if you eliminate the = sign, because it's got brackets [ ] instead of parentheses ( ).

There is nothing in the (correct) form
Image(Pro|Mobile|Searcher)
that could possibly match Googlebot-Image, so that's not a concern.
8:44 pm on Apr 19, 2015 (gmt 0)

Senior Member

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Nov 11, 2001
posts:5507
votes: 5


There are many different UA's you combine into one, and in a similar manners.

In your example one line works for all three:
#begins with Image
RewriteCond %{HTTP_USER_AGENT} ^Image [OR]

The chances that a valid innocent will use the begins with is highly unlikely.
10:56 pm on Apr 19, 2015 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 1, 2012
posts: 86
votes: 0


Thanks for the help. This clears up some misunderstandings I had.