# =============================================
# .htaccess – Prøvelapp-app
# Legg denne i rot-mappen på Dedia
# =============================================

# PHP og encoding
AddDefaultCharset UTF-8
php_value default_charset UTF-8

# Sikkerhet – skjul filer
Options -Indexes
Options -MultiViews

# Blokker direkte tilgang til api-mappen via URL (brukere går via index.html)
# API-kallene fungerer fortsatt fra JavaScript

# Beskytt konfigurasjonsfil
<Files "config.php">
    Order allow,deny
    Deny from all
</Files>

# Ikke vis mappeinnhold
<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

# Komprimering for raskere lasting
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>

# Cache-innstillinger for bilder
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 week"
</IfModule>

# Redirect alle forespørsler til index.html (SPA-støtte)
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # La API-kallene gå direkte til PHP-filene
    RewriteRule ^api/ - [L]

    # La uploads gå direkte
    RewriteRule ^uploads/ - [L]

    # Alt annet går til index.html
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
