Reputation: 1301
The issue: I want to enable directory indexing for a certain directory on my server (it's disabled by default) only for a certain user agent.
I know that there are <If> instructions that can be used in a .htaccess file, but I have not managed to get a result.
What I'm looking for is something along these lines:
<If user-agent = 'a certain user agent'>
Options +Indexes
</if>
I know that there are environment variables that can be set based on various conditions (like a certain user agent) and I have been able to set them according to my needs, bu I was not able to do a simple "if variable is set, then set Options +Indexes" statement
Suggestions? Pointers? Is this even possible? I do not have access to the Apache global configuration file.
Upvotes: 2
Views: 1055
Reputation: 7739
As a solution, you can allow directory indexing to everybody, and then forbidden access to directories for those who don't meet some conditions using rewrite rules.
As an example (Forbidden directory indexing to everybody except googlebot) :
Options +Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_USER_AGENT} !googlebot [NC]
RewriteRule . - [F]
Upvotes: 1