<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"
  Header always set Content-Security-Policy "upgrade-insecure-requests;"
</IfModule>

ErrorDocument 404 /404.html

# Protect sensitive files (Compatible with Apache 2.2 and 2.4+)
<FilesMatch "^\.(env|git|htaccess|htpasswd)">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</FilesMatch>

<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine on

  # 1. Localhost subfolder rewrite (XAMPP: http://localhost/multiclash/ or other local subfolders)
  RewriteCond %{REQUEST_URI} ^/(EliteClash|FlashClash|multiclash)/(.*)$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !maintenance
  RewriteCond %{REQUEST_URI} !cron
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

  # 2. cPanel / Domain Root rewrite (e.g. https://web-app.eliteclash.site/...)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !maintenance
  RewriteCond %{REQUEST_URI} !cron
  RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^maintenance/([0-9a-zA-Z_-]+) maintenance.html [NC,L]
</IfModule>

# Gzip / Deflate compression for fast page transfers
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml image/svg+xml
</IfModule>

# For Leverage browser caching
<IfModule mod_expires.c>
  ExpiresActive On

  # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
