<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Redirect all requests to index.html except files or directories
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

# Disable HTTP/2 (to check if HTTP/2 is causing the issue)
<IfModule mod_http2.c>
  H2Disable On
</IfModule>

# Enable Gzip compression (for better performance)
<IfModule mod_deflate.c>
  # Compression for text, HTML, XML, CSS, and JavaScript
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml
  # Compression for older browsers
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

# Disable Gzip temporarily (if it causes issues under HTTP/2, uncomment below line)
# SetEnv no-gzip 1

# Increase file upload size limits (adjust according to your needs)
<IfModule mod_php.c>
  php_value upload_max_filesize 50M
  php_value post_max_size 50M
  php_value memory_limit 256M
  php_value max_execution_time 300
</IfModule>

# Enable caching for static assets
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/html "access plus 1 day"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/json "access plus 1 month"
  ExpiresByType application/xml "access plus 1 month"
</IfModule>

# Cache-control headers to leverage browser caching
<IfModule mod_headers.c>
  Header set Cache-Control "max-age=31536000, public"
</IfModule>

# Enable file-based ETags
<IfModule mod_headers.c>
  FileETag MTime Size
</IfModule>

# CORS headers (for file upload and API calls)
<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"
  Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
  Header set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
</IfModule>

# Security headers (recommended for protection)
<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "DENY"
  Header always set X-XSS-Protection "1; mode=block"
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
