# ==============================================================================
# PHMACAO APACHE / LITESPEED CONFIGURATION
# 301 Redirects, HTTPS Enforcement, Error Document, and Fast Indexing Caching
# ==============================================================================

RewriteEngine On

# 1. Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# 2. Error Document 404 Handler
ErrorDocument 404 /404.html

# 3. 301 Redirect non-existing URLs to Homepage (or 404)
# If requested filename is not a real file and not a real directory:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [R=301,L]

# 4. Leverage Browser Caching for Assets
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>
