# put the RewriteLock outside your virtual hosts
RewriteLock "/var/cache/thruk/apache_rewrite.lock"

# put everything else inside your vhost
RewriteMap  thruk_users prg:/usr/share/thruk/thruk_auth
RewriteCond %{REQUEST_URI}           !^/thruk/cgi-bin/restricted.cgi
RewriteCond %{REQUEST_URI}            ^/thruk                          # limit thruk cookie auth to thruk itself in standalone mode
RewriteCond %{HTTP_COOKIE}           (thruk_auth=[^;]+|$)  [NC]
RewriteRule ^/(.*)$                  /auth:%1/%{REMOTE_ADDR}~~%{HTTP:Authorization}~~%{HTTP:X-Thruk-Auth-Key}~~%{HTTP:X-Thruk-Auth-User}/____/$1/____/%{QUERY_STRING} [C,NS]
RewriteRule ^(.*)$                   ${thruk_users:$1|/loginbad/} [C,NS]
RewriteRule ^/pass/(.*)$             /$1 [NS,PT,L,E=!REMOTE_USER]
RewriteRule ^/redirect/(.*)$         /$1 [NS,L,R=302]
RewriteRule ^/loginok/([^/]+)/(.*)$  /$2 [NS,PT,L,E=REMOTE_USER:$1]

<LocationMatch ^/thruk(?!/cgi-bin/restricted.cgi)>
  Order allow,deny
  Allow from all
  Satisfy any
</LocationMatch>

AllowEncodedSlashes NoDecode
