# Disable directory listing
Options -Indexes

# Security - Block sensitive files
<Files ~ "^\.">
    Require all denied
</Files>

<FilesMatch "\.(ini|log|conf|config|map)$">
    Require all denied
</FilesMatch>

<FilesMatch "\.(backup|bak|old|orig|swp|save)$">
    Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Admin routes: /admin/login → admin.php?route=login
    RewriteRule ^admin$ admin.php?route=dashboard [L,QSA]
    RewriteRule ^admin/(.+)$ admin.php?route=$1 [L,QSA]

    # Language-prefixed page routes: /nl, /en, /nl/page/path
    RewriteRule ^(nl|en)/?$ index.php?lang=$1 [L,QSA]
    RewriteRule ^(nl|en)/(.+)$ index.php?lang=$1&page=$2 [L,QSA]

    # Root
    RewriteRule ^$ index.php [L]

    # Serve existing static files directly
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # Block directory listing for remaining physical dirs
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [F]

    # Fallback to index.php
    RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

# Security headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options nosniff
    Header always set X-Frame-Options DENY
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self';"
</IfModule>

<IfModule mod_php.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value max_execution_time 30
    php_value memory_limit 128M
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
</IfModule>

DirectoryIndex index.php
ErrorDocument 404 /index.php
