Client Agent dependent protection

Discussion in 'Setting-up protection' started by skippybosco, Jun 10, 2009.

  1. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    User Agent conditional rules

    Has anyone experimented with user agent based conditional rules in .htaccess?
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Following back up on this thread to provide some additional information to see if it sparks any ideas.

    Scenario is that we would want to have different protection based on the browser/user-agent that is accessing the directory. More specifically, we would want iTunes to use Basic Auth whereas all other browsers would use new_rewrite.

    A working example of a .htaccess based user_agent conditional based rule, to give you an idea of what I'm talking about, would be:

    Code:
    SetEnvIfNoCase "User-Agent" "itunes" itunes
    Order Deny,Allow
    Deny from all
    Allow from env=itunes
    satisfy any
    Which would allow any Internet Explorer to view directory, but deny everyone else.

    So taking that logic, I want to say:

    If user_agent = itunes do this:

    Code:
    AuthType Basic
    AuthName "Members Only"
    AuthUserFile /home/mydomain.com/amember/data/.htpasswd
    AuthGroupFile /home/mydomain.com/amember/data/.htgroup
    Require valid-user
    else everyone else do this:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_COOKIE} amember_nr=([a-zA-Z0-9]+)
    RewriteCond /home/mydomain.com/amember/data/new_rewrite/%1 -f 
    RewriteRule ^(.*)$ - [L]
    Any ideas/suggestions?

    Thanks in advance!!

Share This Page