Goal: using a .htaccess file in /directory/, if request URI does NOT exactly match "/directory/" then set a header. For example, the header SHOULD be set if the request URI is "/directory/index.php", "/directory/?something", or "/directory/index.php?something", but should NOT be set if the request URL is exactly "/directory/"
Apache/2.4.41 so the IF directive is available.
Main two methodologies I've attempted:
<If "%{REQUEST_URI} != '/directory/'">
Header always set X-Robots-Tag "noindex"
</If>
SetEnvIf Request_URI "/directory/" isgood
Header always set X-Robots-Tag "noindex" env=!isgood
I've tried a number of variations, such as using "early" on the header, as well as trying to match just "/" based on past experience that when working in an .htaccess context it might not "see" the full URI.
All attempts result in either the header ALWAYS being set or NEVER being set.
(Yes, mod_header and mod_setenvif are enabled)
I rigged this up for testing, trying a few different methods at once with different headers:
<If "%{REQUEST_URI} != '/'">
Header always set X-Test1 "test1"
</If>
<If "%{REQUEST_URI} != '/files/crackypics/2005-January-alt/'">i
Header always set X-Test2 "test2"
</If>
SetEnvIf Request_URI "/" test3
Header always set X-Test3a "test3a" env=!test3
Header always set X-Test3b "test3b" env=test3
SetEnvIf Request_URI "/files/crackypics/2005-January-alt/" test4
Header always set X-Test4a "test4a" env=!test4
Header always set X-Test4b "test4b" env=test4
Regardless of the actual request URI, I always get test1, test2, test3b, and test4b.