RewriteEngine On

# /favicon.ico → doğru PNG (tarayıcı varsayılanı; eski yatay .ico ile çakışmayı önler)
RewriteRule ^favicon\.ico$ /favicon.png?v=20260406 [L,R=301]

# Handle Angular and Flutter routing
# Send all requests to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.html [L]

# Optional: Enable gzip compression (FCP/LCP – document latency azaltır)
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/manifest+json
</IfModule>

# Source maps (flutter build web --source-maps) – DevTools "Missing source maps" uyarısı için
<IfModule mod_mime.c>
    AddType application/json .map
</IfModule>

# Cache static assets - Optimized cache lifetimes
<IfModule mod_expires.c>
    ExpiresActive on
    
    # HTML - Short cache (1 hour) for dynamic content
    ExpiresByType text/html "access plus 1 hour"
    
    # CSS and JavaScript - Long cache (1 year) with versioning
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/x-javascript "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"
    
    # Images - Long cache (1 year)
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    
    # Fonts - Long cache (1 year)
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    
    # JSON and other data - Medium cache (1 week)
    ExpiresByType application/json "access plus 1 week"
    ExpiresByType application/manifest+json "access plus 1 week"
    ExpiresByType application/xml "access plus 1 week"
    ExpiresByType text/xml "access plus 1 week"
    
    # ✅ Video files - Long cache (1 year)
    ExpiresByType video/mp4 "access plus 1 year"
    ExpiresByType video/webm "access plus 1 year"
    ExpiresByType video/ogg "access plus 1 year"
    ExpiresByType video/quicktime "access plus 1 year"
    
    # ✅ WebAssembly files - Long cache (1 year)
    ExpiresByType application/wasm "access plus 1 year"
</IfModule>

# Cache-Control headers for better control
<IfModule mod_headers.c>
    # Cache static assets for 1 year
    <FilesMatch "\.(css|js|jpg|jpeg|png|gif|webp|svg|ico|woff|woff2|ttf|otf|wasm|mp4|webm|ogg)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    
    # Don't cache HTML files
    <FilesMatch "\.(html|htm)$">
        Header set Cache-Control "public, max-age=3600, must-revalidate"
    </FilesMatch>
    
    # Enable CORS for fonts
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
    
    # ✅ Best Practices: Security headers
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    
    # ✅ Best Practices: HSTS (HTTP Strict Transport Security) - HTTPS için
    # Not: Sadece HTTPS üzerinden servis ediliyorsa aktif edin
    # Eğer siteniz HTTPS üzerinden servis ediliyorsa, aşağıdaki satırın başındaki # işaretini kaldırın:
    # Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    
    # ✅ Best Practices: COOP (Cross-Origin-Opener-Policy) - Clickjacking koruması
    Header set Cross-Origin-Opener-Policy "same-origin-allow-popups"
    
    # ✅ Best Practices: CSP (Content Security Policy) - XSS koruması
    # Not: Flutter web için gerekli 'unsafe-inline' ve 'unsafe-eval' kullanılıyor
    # 3rd party script'ler (GTM, Facebook, Google Sign-In) için gerekli domain'ler eklendi
    Header set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.googletagmanager.com https://www.google-analytics.com https://accounts.google.com https://connect.facebook.net https://www.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com data:; img-src 'self' data: https: blob:; connect-src 'self' https://www.google-analytics.com https://www.googletagmanager.com https://connect.facebook.net https://accounts.google.com https://www.facebook.com; frame-src 'self' https://www.youtube.com https://player.vimeo.com https://www.googletagmanager.com https://accounts.google.com; worker-src 'self' blob:; media-src 'self' https: data:; object-src 'none'; base-uri 'self';"
</IfModule>