# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes

# Force HTTPS + WWW (No Rewrite Loop)
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.thereportcubes\.com$ [NC]
RewriteRule ^(.*)$ https://www.thereportcubes.com/$1 [L,R=301]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Remove Trailing Slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Remove index.php from URL
RewriteCond %{THE_REQUEST} \s/+index\.php[\s?] [NC]
RewriteRule ^index\.php(.*)$ $1 [R=301,NC,L]

# WordPress Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# END WordPress


# Hide sensitive files
<FilesMatch "(\.env|composer\.json|package\.json|\.env\.example)">
    Order allow,deny
    Deny from all
</FilesMatch>

# CORS fonts
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

# Cache & Expiry
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "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"
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/otf "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(html|htm)$">
    Header set Cache-Control "max-age=7200, private, must-revalidate"
  </FilesMatch>
  <FilesMatch "\.(js)$">
    Header set Cache-Control "max-age=2678400, private"
  </FilesMatch>
</IfModule>

# Gzip Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE font/ttf font/otf
</IfModule>

# PHP 8.2 Handler
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82___lsphp .php .php8 .phtml
</IfModule>
