# =====================================================
# Detay Enerji - LiteSpeed Optimized .htaccess
# =====================================================

# Enable Rewrite Engine
RewriteEngine On
# RewriteBase kaldırıldı - Apache .htaccess dizinini otomatik kullanır
# Hem /detayenerji/ (local) hem / (production) çalışır

# =====================================================
# HTTPS Redirect (Production)
# =====================================================
# LARAGON LOCAL: HTTPS kapalı, localde çalışmıyor
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# WWW Redirect (www olmadan yönlendir)
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# =====================================================
# Security Headers
# =====================================================
<IfModule mod_headers.c>
    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"
</IfModule>

# =====================================================
# LiteSpeed Cache Ayarları
# =====================================================
<IfModule LiteSpeed>
    # Cache aktif
    CacheEnable public /

    # Statik dosyalar için cache
    <FilesMatch "\.(css|js|jpg|jpeg|png|gif|webp|svg|ico|woff|woff2|ttf|eot)$">
        Header set Cache-Control "max-age=31536000, public"
    </FilesMatch>

    # HTML ve PHP için kısa cache
    <FilesMatch "\.(html|php)$">
        Header set Cache-Control "max-age=3600, public, must-revalidate"
    </FilesMatch>
</IfModule>

# =====================================================
# Browser Caching (Expires)
# =====================================================
<IfModule mod_expires.c>
    ExpiresActive On

    # Default
    ExpiresDefault "access plus 1 month"

    # HTML
    ExpiresByType text/html "access plus 1 hour"

    # CSS & JavaScript
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"

    # Images
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "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"

    # Fonts
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>

# =====================================================
# GZIP Compression
# =====================================================
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# =====================================================
# Hotlink Protection (Görsel Hırsızlığı Engelle)
# =====================================================
# RewriteCond %{HTTP_REFERER} !^$
# RewriteCond %{HTTP_REFERER} !^https?://(www\.)?detayenerji\.com [NC]
# RewriteRule \.(jpg|jpeg|png|gif|webp)$ - [F,NC]

# =====================================================
# Block Bad Bots
# =====================================================
<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_USER_AGENT} (MJ12bot|AhrefsBot|SemrushBot|DotBot) [NC]
    RewriteRule .* - [F,L]
</IfModule>

# =====================================================
# Sitemap Redirect
# =====================================================
RewriteRule ^sitemap\.xml$ sitemap.php [L]

# =====================================================
# Remove trailing slash
# =====================================================
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [L,R=301]

# =====================================================
# Front Controller - Route all requests to index.php
# =====================================================
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

# =====================================================
# Error Pages
# =====================================================
# ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

# =====================================================
# Disable Directory Browsing
# =====================================================
Options -Indexes

# =====================================================
# Protect Sensitive Files
# =====================================================
<FilesMatch "(^\.htaccess|\.env|composer\.json|composer\.lock|\.git)">
    Order allow,deny
    Deny from all
</FilesMatch>

# Block access to src folder
<IfModule mod_rewrite.c>
    RewriteRule ^src/ - [F,L]
    RewriteRule ^views/ - [F,L]
    RewriteRule ^components/ - [F,L]
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php -- END cPanel-generated handler, do not edit
