# تفعيل محرك إعادة الكتابة
RewriteEngine On

# تعيين المجلد الأساسي
RewriteBase /

# إعادة توجيه الطلبات إلى index.php إذا لم تكن ملفًا أو مجلدًا موجودًا
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

# منع الوصول إلى ملفات .htaccess
<Files .htaccess>
    Order Allow,Deny
    Deny from all
</Files>

# منع الوصول إلى ملفات .env
<Files ~ "\.env$">
    Order Allow,Deny
    Deny from all
</Files>

# منع الوصول إلى ملفات .php في مجلد uploads
<FilesMatch "\.php$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order Allow,Deny
        Deny from all
    </IfModule>
</FilesMatch>

# تعيين الصفحة الافتراضية
DirectoryIndex index.php

# تعيين ترميز UTF-8
AddDefaultCharset UTF-8

# تعيين منطقة زمنية
SetEnv TZ Asia/Riyadh

# تفعيل ضغط GZIP
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json
</IfModule>

# تعيين رؤوس الأمان
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
</IfModule>

# تعيين رؤوس التخزين المؤقت
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
</IfModule>
