# ============================================================
#  حديث الموبيليا — إعدادات الأمان والأداء (Apache / LiteSpeed)
# ============================================================
Options -Indexes -MultiViews
ServerSignature Off
AddDefaultCharset UTF-8
DirectoryIndex index.php
LimitRequestBody 52428800

<IfModule mod_php.c>
  php_flag expose_php Off
  php_flag display_errors Off
  php_value session.cookie_httponly 1
</IfModule>

# ملفات حساسة: نسخ احتياطية، قواعد بيانات، سجلات، ملفات مخفية
<FilesMatch "(\.(sql|log|bak|old|ini|sh|md|zip|tar|gz|rar|7z|env|swp|dist|lock)|~)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
</FilesMatch>
<FilesMatch "^(\.|error_log$)">
  <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 set X-Frame-Options "DENY"
  Header set X-Content-Type-Options "nosniff"
  Header set Referrer-Policy "same-origin"
  Header always unset X-Powered-By
  <FilesMatch "\.(css|js|svg|png|ttf|woff2)$">
    Header set Cache-Control "public, max-age=604800"
  </FilesMatch>
</IfModule>

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

<IfModule mod_rewrite.c>
  RewriteEngine On
  # GET و POST فقط
  RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$
  RewriteRule ^ - [R=405,L]
  # منع المجلدات الداخلية والمسارات المخفية (عدا .well-known لشهادة SSL)
  RewriteRule ^inc(/|$) - [F,L]
  RewriteRule (^|/)\.(?!well-known(/|$)) - [F,L]
  # أدوات الفحص والاختراق المعروفة
  RewriteCond %{HTTP_USER_AGENT} (sqlmap|nikto|wpscan|nmap|masscan|acunetix|nessus|nuclei|dirbuster|gobuster|havij|w3af) [NC]
  RewriteRule ^ - [F,L]
  # أنماط هجوم في الرابط
  RewriteCond %{QUERY_STRING} (\.\./|%2e%2e) [NC,OR]
  RewriteCond %{QUERY_STRING} (<|%3c).*(script|iframe).*(>|%3e) [NC,OR]
  RewriteCond %{QUERY_STRING} union.*select [NC,OR]
  RewriteCond %{QUERY_STRING} (etc/passwd|php://|file://|data://) [NC]
  RewriteRule ^ - [F,L]
  # تحويل إلى HTTPS على الاستضافة فقط (ليس على الجهاز المحلي)
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteCond %{HTTP_HOST} !^(localhost|127\.0\.0\.1|192\.168\.|10\.)(.*)$ [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  # روابط نظيفة: /orders بدل /orders.php (الطلبات GET فقط تُحوَّل؛ POST يعمل كما هو)
  RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
  RewriteCond %{THE_REQUEST} \s/[^\s?]*\.php(\?[^\s]*)?\sHTTP/
  RewriteCond %{REQUEST_URI} ^(.+)\.php$
  RewriteRule ^ %1 [R=301,L,QSA]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^(.+)$ $1.php [L]
</IfModule>

<IfModule mod_mime.c>
  AddType font/ttf .ttf
  AddType font/woff2 .woff2
</IfModule>
