RewriteEngine On

# --- Kanonische Adresse: HTTPS erzwingen, nackte Domain auf www ---
# Die Formulare übertragen Name, Adresse und Geburtsdatum — nie über http.
# Der HTTPS-Redirect ist bewusst host-neutral (funktioniert auch auf einer
# Test-/Preview-Domain); nur tsv08kulmbach.de wird hart auf www gezogen.
# Drei unabhängige TLS-Indikatoren, damit kein Redirect-Loop entsteht, falls der
# Hoster die Verschlüsselung anders durchreicht als erwartet.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1)(:[0-9]+)?$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^tsv08kulmbach\.de$ [NC]
RewriteRule ^ https://www.tsv08kulmbach.de%{REQUEST_URI} [R=301,L]

# --- Front Controller ---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

# --- Security-Header ---
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
    # HSTS nur über HTTPS ausliefern (1 Jahr, ohne includeSubDomains — Subdomains
    # wie Webmail liegen nicht in unserer Hand).
    Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
    # Streng möglich, weil ausnahmslos alles self-hosted ist (CLAUDE.md Regel 1).
    Header always set Content-Security-Policy "default-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'"
</IfModule>

# --- Kompression ---
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

# --- Caching: Assets 1 Jahr (Busting via ?v=filemtime), HTML nie ---
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType image/jpeg "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"
    ExpiresByType video/mp4 "access plus 1 year"
    ExpiresByType text/html "access plus 0 seconds"
</IfModule>

AddType font/woff2 .woff2
AddDefaultCharset utf-8
Options -Indexes
