# ---- Votimens sunucu güvenliği (Apache) ----

# Klasör içeriklerinin listelenmesini kapat
Options -Indexes
ServerSignature Off

# Gizli ve yapılandırma dosyalarına web'den erişimi engelle
<FilesMatch "^(\.env.*|\.gitignore|\.htaccess|\.DS_Store|database\.php|composer\.(json|lock)|package(-lock)?\.json)$">
    Require all denied
</FilesMatch>
<FilesMatch "\.(sql|log|bak|ini|sh|scss|md)$">
    Require all denied
</FilesMatch>

# Canlı sunucuda HTTP'yi HTTPS'e yönlendir (localhost hariç)
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !=https
    RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1|\[::1\])(:[0-9]+)?$ [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # robots.txt ve sitemap.xml site adresine göre dinamik üretilir
    RewriteRule ^robots\.txt$ robots.php [L]
    RewriteRule ^sitemap\.xml$ sitemap.php [L]

    # Bulunamayan sayfalar için özel 404 sayfası (görsel/stil dosyaları hariç)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif|svg|webp|ico|css|js|map|woff2?|ttf|eot|txt|xml)$ [NC]
    RewriteRule ^ 404.php [L]
</IfModule>

# Güvenlik başlıkları
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "camera=(), microphone=()"
    Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
</IfModule>
