# Apache ve LiteSpeed için temel yapılandırma.
# Nginx kullanıyorsanız docs/nginx.md dosyasındaki kuralları uygulayın.

# mHaber LSCache başlangıç
# LiteSpeed sunucu önbelleği: herkese açık sayfalar PHP çalışmadan sunulur.
# Oturum çerezi taşıyan istekler (yönetim paneli, giriş yapmış okur) önbelleği atlar.
<IfModule LiteSpeed>
    CacheLookup public on
    RewriteEngine On
    RewriteCond %{HTTP_COOKIE} (^|;\s*)(__Host-)?sid= [NC]
    RewriteRule .* - [E=Cache-Control:no-cache]
</IfModule>
# Statik dosyalar bir yıl saklanır: varlık adresleri sürüm parametresi (?v=) taşır,
# yüklenen medya benzersiz adlıdır. Bildirim hizmet çalışanı (sw.js) her seferinde denetlenir.
<IfModule mod_headers.c>
    <FilesMatch "\.(css|js|woff2|svg|png|jpe?g|gif|webp|avif|ico|mp3|m4a|ogg|mp4|webm)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    <Files "sw.js">
        Header set Cache-Control "no-cache"
    </Files>
</IfModule>
# mHaber LSCache bitiş

Options -Indexes -MultiViews
DirectoryIndex index.php
ServerSignature Off

# index.php dışındaki hiçbir PHP dosyası doğrudan çalıştırılamaz.
# Şablon, veritabanı dökümü, log ve yapılandırma uzantıları dışarıya kapalıdır.
<FilesMatch "\.(php|php[0-9]|phtml|phar|inc|tpl|sql|sqlite|log|lock|ini|bak|old|orig|swp|dist|sh|env)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

<Files "index.php">
    <IfModule mod_authz_core.c>
        Require all granted
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Allow from all
    </IfModule>
</Files>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Nokta ile başlayan dosya ve dizinler (.git, .env vb.) kapalıdır; .well-known hariç.
    RewriteRule (^|/)\.(?!well-known(/|$)) - [F,L]

    # Uygulama kodu ve depolama dizinleri web üzerinden erişilemez.
    RewriteRule ^(app|storage)(/|$) - [F,L]

    # Var olan statik dosyalar doğrudan sunulur, geri kalan her istek index.php'ye gider.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always unset X-Powered-By
</IfModule>

# Metin yanıtlarının sıkıştırılması (brotli varsa önce o kullanılır).
<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/xml application/xml application/rss+xml application/atom+xml application/javascript text/javascript application/json application/ld+json application/manifest+json image/svg+xml
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/rss+xml application/atom+xml application/javascript text/javascript application/json application/ld+json application/manifest+json image/svg+xml
</IfModule>

<IfModule mod_mime.c>
    AddType font/woff2 .woff2
    AddType image/avif .avif
    AddType image/webp .webp
</IfModule>
