# حِسبة — إعدادات الخادم (Apache / LiteSpeed على هوستنجر)
Options -MultiViews -Indexes
RewriteEngine On

# 1) فرض HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# 2) نسخة واحدة من الدومين: بدون www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# 3) /index.html أو /index ← /
RewriteCond %{THE_REQUEST} \s/+index(\.html)?[\s?] [NC]
RewriteRule ^ / [L,R=301]

# 4) /page.html ← /page (روابط نظيفة بدون تكرار المحتوى)
RewriteCond %{THE_REQUEST} \s/+([^.\s?]+)\.html[\s?] [NC]
RewriteRule ^ /%1 [L,R=301]

# 5) إزالة الشرطة الأخيرة: /page/ ← /page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [L,R=301]

# 6) خدمة /page من page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([a-z0-9-]+)$ $1.html [L]

ErrorDocument 404 /404.html

# ضغط الملفات النصية
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml application/xml text/plain
</IfModule>

# التخزين المؤقت: ملفات CSS/JS تحمل رقم إصدار (?v=) فيمكن تخزينها طويلًا
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
</IfModule>

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set X-Frame-Options "SAMEORIGIN"
  <FilesMatch "\.html$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
</IfModule>
