# Bibliotheksverwaltung - Apache Configuration
# Security & URL Rewriting

# Disable directory browsing
Options -Indexes

# Enable URL rewriting
<IfModule mod_rewrite.c>
    RewriteEngine On
    # RewriteBase will be auto-detected
    
    # Redirect to HTTPS (optional, uncomment if needed)
    # RewriteCond %{HTTPS} off
    # RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Protect sensitive files
    RewriteRule ^includes/ - [F,L]
    RewriteRule ^install/(?!.*\.php$|steps/) - [F,L]
    RewriteRule ^backups/ - [F,L]
    RewriteRule ^vendor/ - [F,L]
    RewriteRule composer\.(json|lock)$ - [F,L]
    RewriteRule \.git - [F,L]
    
    # Installation redirect handled by index.php
</IfModule>

# Security Headers
<IfModule mod_headers.c>
    # Prevent clickjacking
    Header always set X-Frame-Options "SAMEORIGIN"
    
    # XSS Protection
    Header always set X-XSS-Protection "1; mode=block"
    
    # Prevent MIME sniffing
    Header always set X-Content-Type-Options "nosniff"
    
    # Referrer Policy
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Protect config files
<FilesMatch "^(config|\.env|\.htaccess|\.git)">
    Order allow,deny
    Deny from all
</FilesMatch>

# PHP Security Settings
<IfModule mod_php.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
    php_value max_execution_time 300
    php_value memory_limit 256M
</IfModule>

# Compress output
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>

# Cache static files
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
</IfModule>

# Error pages (optional)
# ErrorDocument 404 /404.php
# ErrorDocument 403 /403.php
# ErrorDocument 500 /500.php
