RewriteEngine On
RewriteBase /

# 1. Admin, API ve Uploads Klasörlerini Dokunma (BU ÇOK ÖNEMLİ)
RewriteRule ^(admin|api|uploads|img|system)($|/) - [L]

# 2. Dosya ve Klasörleri Yoksay
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# 3. Özel Sayfalar
RewriteRule ^sepet$ templates/ajax_sepet.php [L,QSA]
RewriteRule ^sepet-odeme$ templates/sepet-odeme.php [L,QSA]
RewriteRule ^siparis-islem$ templates/siparis-islem.php [L,QSA]
RewriteRule ^siparis-sorgula$ templates/siparis-takip.php [L,QSA]
RewriteRule ^odeme-yap$ templates/odeme.php [L,QSA]
RewriteRule ^urundetaygit$ templates/urun-detay.php [L,QSA]
RewriteRule ^havale-bildirim$ templates/havale-bildirim.php [L,QSA]
RewriteRule ^odeme-sonuc$ templates/odeme-sonuc.php [L,QSA]

# 4. Sayfa Linki: site.com/sayfa/hakkimizda
RewriteRule ^sayfa/(.*)$ index.php?sayfa_slug=$1 [L,QSA]

# 5. Kategori Linki: pasta-k9
RewriteRule ^(.*)-k([0-9]+)$ index.php?kat=$2 [L,QSA]

# 6. Ürün Linki: 12-cikolatali-pasta
RewriteRule ^([0-9]+)-(.*)$ templates/urun-detay.php?id=$1 [L,QSA]

# 7. Güvenlik
<FilesMatch "\.(json|log|txt)$">
    Order Deny,Allow
    Deny from all
</FilesMatch>


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^\.git - [F,L]
</IfModule>




<IfModule mod_deflate.c>
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ 
            HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE application/atom+xml \
        application/javascript \
        application/json \
        application/rss+xml \
        application/vnd.ms-fontobject \
        application/x-font-ttf \
        application/xhtml+xml \
        application/xml \
        font/opentype \
        font/woff \
        font/woff2 \
        image/svg+xml \
        image/x-icon \
        text/css \
        text/html \
        text/plain \
        text/x-component \
        text/xml
    </IfModule>

</IfModule>
      


# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset utf-8

# Force UTF-8 for a number of file formats
<IfModule mod_mime.c>
    AddCharset utf-8 .atom .css .js .json .rss .vtt .xml
</IfModule>



               
<IfModule mod_expires.c>  
  # Turn on the module.
  ExpiresActive on
  ExpiresDefault A3600

  # Set the default expiry times.
  ExpiresDefault "access plus 2 days"
  ExpiresByType image/jpg "access plus 12 month"
  ExpiresByType image/svg+xml "access 12 month"
  ExpiresByType image/gif "access plus 12 month"
  ExpiresByType image/jpeg "access plus 12 month"
  ExpiresByType image/png "access plus 12 month"
  ExpiresByType image/webp "access plus 12 month"
  ExpiresByType text/css "access plus 12 month"
  ExpiresByType text/javascript "access plus 12 month"
  ExpiresByType application/javascript "access plus 12 month"
  ExpiresByType application/x-shockwave-flash "access plus 121 month"
  ExpiresByType image/ico "access plus 12 month"
  ExpiresByType image/x-icon "access plus 12 month"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/json "access plus 1 hour"
  ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>

# ETag kaldır (CPU kullanımını azalt)
<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None

# Keep-Alive etkinleştir
<IfModule mod_headers.c>
    Header set Connection keep-alive
</IfModule>

# Preconnect harici kaynaklara
<IfModule mod_headers.c>
    <FilesMatch "\.(html|php)$">
        Header append Link "<https://fonts.googleapis.com>; rel=preconnect"
        Header append Link "<https://fonts.gstatic.com>; rel=preconnect; crossorigin"
        Header append Link "<https://cdn.jsdelivr.net>; rel=preconnect"
        Header append Link "<https://cdnjs.cloudflare.com>; rel=preconnect"
    </FilesMatch>
</IfModule>