# Admin Directory - Security Protection
<IfModule mod_rewrite.c>
  RewriteEngine On
  
  # Allow direct web requests to admin pages
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

# Prevent Directory Listing
Options -Indexes

# =====================================================
# ALLOW ACCESS TO ADMIN FILES
# =====================================================
<FilesMatch "\.php$">
  <IfModule mod_authz_core.c>
    Require all granted
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Allow from all
  </IfModule>
</FilesMatch>

# Block access to .htaccess files
<Files ".htaccess">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</Files>

# Prevent access via query string to non-.php files
<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_URI} !\.php$
  RewriteCond %{QUERY_STRING} [a-z]
  RewriteRule .* - [L,F]
</IfModule>

# Security Headers
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-XSS-Protection "1; mode=block"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  Header set Cache-Control "no-cache, no-store, must-revalidate"
</IfModule>

# Prevent caching of admin pages
<IfModule mod_headers.c>
  <FilesMatch "\.php$">
    Header set Cache-Control "no-cache, no-store, must-revalidate, private"
    Header set Pragma "no-cache"
    Header set Expires "0"
  </FilesMatch>
</IfModule>
