# V2-Plattform — clean URLs
# Lokal:    http://localhost/geograsim/v2-platform/...
# Prod:     https://geograsim.at/v2beta/...

RewriteEngine On

# Authorization-Header an PHP durchreichen (Apache reicht ihn von Haus aus nicht durch)
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Security: keine Direktzugriffe auf .env, .sql, .log
<FilesMatch "\.(env|env\.local|sql|log)$">
  Order Allow,Deny
  Deny from all
</FilesMatch>

# Security: keine Direktzugriffe auf db/ und logs/
RewriteRule ^db/ - [F,L]
RewriteRule ^logs/ - [F,L]

# CORS für Modul-Frontend → API (gleiche Origin, normalerweise nicht nötig,
# aber für Entwicklung mit verschiedenen Ports hilfreich)
<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"
</IfModule>

# Pretty-API-URLs
# /api/student/me → /php/api/student/me.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.+)$ php/api/$1.php [L]
