# SSL Sertifikası için HTTP'den HTTPS'ye Yönlendirme
<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # HTTP'den HTTPS'ye yönlendirme
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # www olmadan yönlendirme (isteğe bağlı)
    # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    # RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [L,R=301]
</IfModule>

# Güvenlik Başlıkları
<IfModule mod_headers.c>
    # XSS Koruması
    Header set X-XSS-Protection "1; mode=block"
    
    # MIME türü sniffing'i engelleme
    Header set X-Content-Type-Options "nosniff"
    
    # Clickjacking koruması
    Header set X-Frame-Options "SAMEORIGIN"
    
    # Referrer Policy
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    
    # Content Security Policy (CSP) - Gerektiğinde özelleştirin
    # Header set Content-Security-Policy "default-src 'self'; script-src 'self' https://cdn.jsdelivr.net https://code.jquery.com https://cdnjs.cloudflare.com; style-src 'self' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com 'unsafe-inline'; img-src 'self' data:; font-src 'self' https://cdnjs.cloudflare.com; connect-src 'self';"
    
    # HSTS (HTTP Strict Transport Security) - SSL sertifikası varsa
    Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>

# PHP Güvenlik Ayarları
<IfModule mod_php.c>
    # PHP hata mesajlarını gizle
    php_flag display_errors off
    php_flag display_startup_errors off
    
    # PHP bilgilerini gizle
    php_flag expose_php off
    
    # Register globals'ı devre dışı bırak (PHP 5.4+ için gerekli değil)
    php_flag register_globals off
    
    # Magic quotes'ı devre dışı bırak (PHP 5.4+ için gerekli değil)
    php_flag magic_quotes_gpc off
    
    # Session güvenliği
    php_flag session.use_only_cookies on
    php_flag session.use_trans_sid off
</IfModule>

# Dizin Listelemeyi Engelle
Options -Indexes

# Dosya Erişimini Kısıtla
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

<FilesMatch "^(composer\.json|composer\.lock|package\.json|package-lock\.json|\.gitignore|\.env|\.htaccess)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# PHP Dosyalarını Koruma
<FilesMatch "\.php$">
    # PHP dosyalarının doğrudan çalıştırılmasını engelle
    # Bu, PHP dosyalarının doğrudan çalıştırılmasını engeller
    # Sadece index.php ve diğer gerekli PHP dosyalarına izin ver
    Order allow,deny
    Allow from all
</FilesMatch>

# Sunucu Bilgilerini Gizle
ServerSignature Off

# MIME Türlerini Ayarla
<IfModule mod_mime.c>
    AddType application/javascript .js
    AddType text/css .css
    AddType image/svg+xml .svg
    AddType application/font-woff .woff
    AddType application/font-woff2 .woff2
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf .ttf
    AddType image/x-icon .ico
</IfModule>

# Tarayıcı Önbelleği
<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 image/svg+xml "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
</IfModule>

# Sıkıştırma
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json application/xml
</IfModule>
