# ==============================================================================
#  waomcoo — إعدادات Apache / LiteSpeed لمجلد public
#  لا تعدّل هذا الملف إلا بطلب من المطوّر.
#  (Do not edit unless instructed. Tuned for shared cPanel hosting.)
# ==============================================================================

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# ------------------------------------------------------------------------------
#  حماية: منع تحميل الملفات المخفية والحسّاسة
#  لو رُفع ملف .env بالخطأ داخل مجلد public، هذه القواعد تمنع تحميله.
#  (استثناء .well-known/ ضروري لتجديد شهادة SSL تلقائياً.)
# ------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule (?:^|/)\.(?!well-known/) - [F,L]
</IfModule>

<FilesMatch "(?i)(^\.env|\.env\.|^composer\.(json|lock)$|^package(-lock)?\.json$|\.(log|sqlite|md|ya?ml|ini|sh|bak|orig|dist)$)">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

# ------------------------------------------------------------------------------
#  ترويسات أمان أساسية
#  تمنع تضمين لوحة التحكم داخل موقع آخر، وتمنع تخمين نوع الملفات.
# ------------------------------------------------------------------------------
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ------------------------------------------------------------------------------
#  ضغط وتسريع (اختياري — يتجاهله السيرفر إن لم يدعم هذه الوحدات)
# ------------------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
    AddOutputFilterByType DEFLATE application/javascript application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    # ملفات لوحة التحكم المبنية تحمل بصمة فريدة في اسمها، فتخزينها طويلاً آمن.
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
</IfModule>

# ==============================================================================
#  ملاحظات للمطوّر (لا تتطلّب أي إجراء من المدير):
#
#  1) إجبار https:
#     لم نضِف قاعدة تحويل http→https هنا عن قصد. معظم استضافات cPanel
#     توفّر هذا الخيار من لوحة التحكم (Domains ← Force HTTPS Redirect)،
#     وتفعيله هناك مع إضافة القاعدة يدوياً هنا في الوقت نفسه يُنتج
#     حلقة تحويل لا نهائية (redirect loop) تُعطّل الموقع بالكامل.
#     إذا لم يوفّر المزوّد الخيار، أزل علامة # من الأسطر التالية:
#
#     # <IfModule mod_rewrite.c>
#     #     RewriteEngine On
#     #     RewriteCond %{HTTPS} !=on
#     #     RewriteCond %{HTTP:X-Forwarded-Proto} !https
#     #     RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#     # </IfModule>
#
#  2) نسخة PHP لا تُضبَط من هذا الملف:
#     استخدم cPanel ← MultiPHP Manager (أو Setup PHP App) واختر 8.4.
#     التفاصيل في DEPLOY-CPANEL.md.
#     بعض الاستضافات تضيف سطر "AddHandler ... .php" تلقائياً أعلى هذا
#     الملف عند تغيير النسخة — هذا طبيعي، اتركه كما هو.
# ==============================================================================
