# Infumia LTD - Apache/cPanel public kurallari
# Document root ideal olarak bu public klasoru olmalidir.

# Dizin listelemeyi kapat
Options -Indexes

# charset
AddDefaultCharset UTF-8
AddType image/x-icon .ico
AddType image/png .png
AddType image/webp .webp
AddType image/avif .avif
AddType font/woff2 .woff2

# Gizli/sistem dosyalarini URL'den kapat
<FilesMatch "^\.|(\.env|\.ini|\.log|\.sql|\.bak|\.backup|\.old|\.orig|\.save|composer\.(json|lock)|package(-lock)?\.json|yarn\.lock)$">
    Require all denied
</FilesMatch>

# Public altinda PHP sadece front controller ve setup icin calissin
<FilesMatch "\.(php|phtml|php3|php4|php5|php7|phps|pht|phar)$">
    Require all denied
</FilesMatch>
<Files "index.php">
    Require all granted
</Files>
<Files "setup.php">
    Require all granted
</Files>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Canli ortamda HTTPS'e zorla, localhost testlerini bozma.
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1)(:\d+)?$ [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # /public/ on ekini URL'den kaldir — 301 ile koke yonlendir.
    # Bu sayede infumia.com/public/app-ads.txt → infumia.com/app-ads.txt olur.
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{THE_REQUEST} ^GET\s/public/ [NC]
    RewriteRule ^public/(.*)$ /$1 [R=301,L]

    # Var olan gerçek dosyalara/dizinlere dokunma (css, js, img, upload vs.)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Geri kalan her şey front controller'a
    RewriteRule ^ index.php [QSA,L]
</IfModule>

# güvenlik başlıkları
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    Header set X-XSS-Protection "1; mode=block"
    Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
    <FilesMatch "\.(css|js|png|jpe?g|gif|svg|webp|avif|ico|woff2?)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

# UTF-8 olan PHP dosyalarından BOM'a izin verme, gzip et
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json
</IfModule>

# cache
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/avif "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
