You need mod-rewrite to capture strings.
|SetEnvIfNoCase User-Agent "chrome" myNewVariable=A |
this line ends reading after the exactly as ("chrome") denying all browsers where the UA contains chrome and never reads the variable string.
Apache does solve some issues on its own, whether the result is what you desire, and/or to your liking, ia another story.
Surprising the line doesn't generate a 500 Error.
From what I can tell according to the documentation at apache.org, the regex for the user agent string can be enclosed in quotes, so I don't think it's doing an exact match, I think it's doing a regex.
Also, the comparison must be evaluating to true, because 'myNewVariable' is being created, and the comparison is exactly the same.
|From what I can tell according to the documentation at apache.org, the regex for the user agent string can be enclosed in quotes, so I don't think it's doing an exact match, |
Try the following two lines (not simultaneously) and you'll see that enclosing within quotes does exactly that
SetEnvIf User-Agent "chrome"
SetEnvIf User-Agent "Chrome"
The first will always fail because no Chrome browser uses the lower-case c.
The second will deny every Chrome visitor to your site (s).
I use quote very sparingly due to this conflict.
I don't understand. I was using SetEnvIfNoCase specifically to avoid case sensitivity issues. It must work, why else would 'myNewVariable' be created correctly?
|Try the following two lines (not simultaneously) and you'll see that enclosing within quotes does exactly that |
I think he meant a full-text match, not a case-sensitive match. SetEnvIf is case-sensitive unless you expressly tell it NoCase.
You can say BrowserMatch (or BrowserMatchNoCase) as a special shortcut for user agents. In fact I never bother with anything else.
Quotation marks are most useful for enclosing strings that contain spaces, since the space would otherwise have syntactic meaning:
BrowserMatch ^-?$ keep_out
BrowserMatch Ahrefs keep_out
BrowserMatch "America Online Browser" keep_out
BrowserMatch Clipish keep_out
BrowserMatch Covario keep_out
BrowserMatch CoverScout keep_out
BrowserMatch "Extreme Picture Finder" keep_out
et cetera. (Quick cut & paste from my shared htaccess).
|Quotation marks are most useful for enclosing strings that contain spaces, since the space would otherwise have syntactic meaning: |
You mean like this:
SetEnvIf User-Agent " ; " keep_out
SetEnvIf User-Agent " \( " keep_out
SetEnvIf User-Agent "; " keep_out
Yup. But watch out: I'd no sooner blocked UAs containing multi-spaces than I ran into a perfectly legitimate human UA that really did have two spaces. They're not all plainclothes bingbots, darn it.
|SetEnvIf User-Agent "; " keep_out |
I assume that one begin life as a double space before the Forums crunched it. You can protect multi-spaces in posts by using nonbreaking spaces, as in html-- but only as long as everyone reading the thread uses the same file encoding. Otherwise some folks will see (A-circumflex with following nbsp) instead.
Now watch as this gets recursive. Only the first 16 Latin-1 characters have this feature.
Oh yes and: mod_setenvif uses Regular Expressions, so you can do package deals like " [);:]".
That's why I was surrounding the string in quotes - in my simple test it's not necessary but in reality it will be because the regex will have spaces.
OK so now that that's out of the way, I guess no one has any idea regarding the actual problem I'm having?
Where are vhost and htaccess located relative to each other? Are they physically in the same directory structure? If so, which one executes first? If I read your first post correctly, you've verified that htaccess is enabled and can use mod_setenvif. That was one essential step.
htaccess is definitely enabled and mod_setenvif must work also, because the new variable is successfully created with SetEnvIfNoCase
I'm not sure where they're located in reference to each other, or which runs first though. I imagine they are in the same directory structure.
I might have said vhost executes second, which would explain why the SetEnvIfNoCase attempt to modify the variable in .htaccess fails. But the SetEnv in .htaccess succeeds in modifying the variable, which implies .htaccess runs after vhost.