# Kuaför Sistemi - URL Yönlendirme ve Güvenlik
# Hosting: Rabisu (emrebaytas.com.tr)

RewriteEngine On

# Güvenlik - Hassas dosyaları gizle
<Files "config/*.php">
    Order allow,deny
    Deny from all
</Files>

<Files "database/*.sql">
    Order allow,deny
    Deny from all
</Files>

<Files ".htaccess">
    Order allow,deny
    Deny from all
</Files>

# Super Admin Panel (xpanel) - Gizli erişim
RewriteRule ^xpanel/?$ xpanel/index.php [L]
RewriteRule ^xpanel/(.*)$ xpanel/$1 [L]

# API Yönlendirmeleri
RewriteRule ^api/(.*)$ api/$1 [L]

# Subdomain Kontrolü ve Yönlendirme
RewriteCond %{HTTP_HOST} ^([^.]+)\.emrebaytas\.com\.tr$ [NC]
RewriteCond %1 !^(www|mail|ftp|admin|api|test|demo)$ [NC]
RewriteRule ^(.*)$ template/index.php?subdomain=%1&page=$1 [QSA,L]

# Demo subdomain özel yönlendirme
RewriteCond %{HTTP_HOST} ^demo\.emrebaytas\.com\.tr$ [NC]
RewriteRule ^(.*)$ template/index.php?subdomain=demo&page=$1 [QSA,L]

# Ana site yönlendirmeleri
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA,L]

# HTTPS Yönlendirme (Güvenlik)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Dosya Uzantılarını Gizle
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Güvenlik Headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options nosniff
    Header always set X-Frame-Options DENY
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Dosya Yükleme Güvenliği
<FilesMatch "\.(php|php3|php4|php5|phtml|pl|py|jsp|asp|sh|cgi)$">
    <IfModule mod_dir.c>
        DirectoryIndex disabled
    </IfModule>
</FilesMatch>

# Cache Ayarları
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "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"
</IfModule>

# Gzip Sıkıştırma
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# Error Pages
ErrorDocument 404 /kuafor-sistem/404.php
ErrorDocument 403 /kuafor-sistem/403.php
ErrorDocument 500 /kuafor-sistem/500.php
