<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # Admin paneli - tüm /admin/* isteklerini koru
    RewriteCond %{REQUEST_URI} ^/admin/
    RewriteRule ^ - [L]
    
    # Uploads klasörü
    RewriteCond %{REQUEST_URI} ^/uploads/
    RewriteRule ^ - [L]
    
    # Assets klasörü
    RewriteCond %{REQUEST_URI} ^/assets/
    RewriteRule ^ - [L]
    
    # Gerçek dosyalar varsa dokunma
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    
    # Gerçek klasörler varsa dokunma
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    # Kategori sayfaları (Türkçe) - ÖNCE kategori/slug/sayfa/X formatı
    RewriteRule ^kategori/([a-zA-Z0-9_-]+)/sayfa/([0-9]+)/?$ category.php?slug=$1&sayfa=$2 [L,QSA]
    RewriteRule ^kategori/([a-zA-Z0-9_-]+)/?$ category.php?slug=$1 [L,QSA]
    
    # Tag sayfaları (Türkçe)
    RewriteRule ^etiket/([a-zA-Z0-9_-]+)/sayfa/([0-9]+)/?$ tag.php?slug=$1&sayfa=$2 [L,QSA]
    RewriteRule ^etiket/([a-zA-Z0-9_-]+)/?$ tag.php?slug=$1 [L,QSA]
    
    # Arama sayfası (Türkçe)
    RewriteRule ^arama/?$ search.php [L,QSA]
    
    # Ana sayfa pagination (Türkçe) - ÖNEMLİ: "sayfa/X" kuralı "sayfa/slug" kuralından ÖNCE olmalı
    RewriteRule ^sayfa/([0-9]+)/?$ index.php?sayfa=$1 [L,QSA]
    
    # Sayfalar için routing (Türkçe) - ÖNEMLİ: Sayfalama kuralından SONRA gelmeli
    RewriteRule ^sayfa/([a-z0-9-]+)/?$ page.php?slug=$1 [L,QSA]
    
    # İletişim sayfası (Türkçe)
    RewriteRule ^iletisim/?$ contact.php [L]
    RewriteRule ^contact/?$ contact.php [L]
        
    # Post detay - en sona (slug çakışmasını önlemek için)
    RewriteRule ^([a-zA-Z0-9_-]+)/?$ post.php?slug=$1 [L,QSA]
</IfModule>

# Güvenlik
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|sql|env)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Dizin listelemeyi kapat
Options -Indexes

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

# Browser Caching (Tarayıcı Önbelleği)
<IfModule mod_expires.c>
    ExpiresActive On
    
    # Resimler - 1 yıl
    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/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    
    # CSS ve JavaScript - 1 ay
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    
    # Fontlar - 1 yıl
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType font/opentype "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
    
    # PDF - 1 ay
    ExpiresByType application/pdf "access plus 1 month"
    
    # HTML - cache yok
    ExpiresByType text/html "access plus 0 seconds"
</IfModule>

# Security Headers (Güvenlik Başlıkları)
<IfModule mod_headers.c>
    # XSS koruması
    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"
    
    # PHP dosyaları için cache kontrolü
    <FilesMatch "\.(php)$">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires 0
    </FilesMatch>
    
    # Statik dosyalar için cache
    <FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|css|js|ico|woff|woff2|ttf|otf)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

# PHP Settings
<IfModule mod_php7.c>
    php_value upload_max_filesize 64M
    php_value post_max_size 64M
    php_value max_execution_time 300
    php_value max_input_time 300
    php_value memory_limit 256M
</IfModule>

# PHP 8.x için
<IfModule mod_php.c>
    php_value upload_max_filesize 64M
    php_value post_max_size 64M
    php_value max_execution_time 300
    php_value max_input_time 300
    php_value memory_limit 256M
</IfModule>

# Error Pages (Hata Sayfaları)
ErrorDocument 404 /404.php
ErrorDocument 403 /403.php
ErrorDocument 500 /500.php