# =====================================================================
# Digisyn Taekwondo — Root .htaccess
# Place this file directly in public_html/ (or wherever site root is).
# =====================================================================

Options -Indexes
ServerSignature Off

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force HTTPS (uncomment after SSL is active)
    # RewriteCond %{HTTPS} !=on
    # RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

    # Strip trailing slash for clean URLs (optional)
    # RewriteCond %{REQUEST_FILENAME} !-d
    # RewriteRule ^(.+)/$ /$1 [R=301,L]
</IfModule>

# Block access to sensitive files
<FilesMatch "\.(env|sql|md|log|ini|sh|bak|old|swp)$">
    Require all denied
</FilesMatch>
<FilesMatch "^\.htaccess$">
    Require all denied
</FilesMatch>

# Security headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    Header set Permissions-Policy "geolocation=(), microphone=(), camera=(self)"
    # Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
</IfModule>

# Cache static assets — longer cache for things with hashed names / immutable
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault                       "access plus 1 hour"
    ExpiresByType image/jpeg             "access plus 6 months"
    ExpiresByType image/png              "access plus 6 months"
    ExpiresByType image/svg+xml          "access plus 1 year"
    ExpiresByType image/webp             "access plus 6 months"
    ExpiresByType image/x-icon           "access plus 1 year"
    ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
    ExpiresByType text/css               "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/font-woff2 "access plus 1 year"
    ExpiresByType font/woff2             "access plus 1 year"
</IfModule>

<IfModule mod_headers.c>
    # Long cache for static files (immutable hint)
    <FilesMatch "\.(css|js|woff2|svg|png|jpg|jpeg|webp|ico)$">
        Header set Cache-Control "public, max-age=2592000"
    </FilesMatch>
    # Never cache PHP responses
    <FilesMatch "\.php$">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
    </FilesMatch>
</IfModule>

# Compression — brotli where available, gzip fallback
<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

# Custom error pages (optional — create these PHP files later)
# ErrorDocument 404 /404.php
# ErrorDocument 500 /500.php
