# ==========================================================
#  تشغيل النظام من الفولدر الرئيسي + حماية ملفات المشروع
#  (يعمل على Apache و LiteSpeed - أغلب استضافات cPanel)
# ==========================================================

Options -Indexes -MultiViews
DirectoryIndex index.php

# منع قراءة الملفات المخفية مثل .env حتى لو كان mod_rewrite متوقفاً
<FilesMatch "^\.">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

<FilesMatch "^(composer\.(json|lock)|artisan|package\.json|phpunit\.xml|vite\.config\.js|README\.md)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # منع الوصول لفولدرات المشروع الداخلية
    RewriteRule ^(app|bootstrap|config|database|lang|resources|routes|storage|tests|vendor)(/|$) - [F,L]

    # تمرير ترويسة Authorization
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # ملفات public الثابتة
    RewriteRule ^(favicon\.ico|robots\.txt)$ public/$1 [L]

    # كل الطلبات الأخرى إلى index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>
