# .htaccess لـ nawahi.invites - Next.js Static Export on cPanel
# ضع هذا الملف في public_html/ (مع ملفات out/)

# ============ Default Landing Page ============
DirectoryIndex index.html

# ============ URL Rewriting (SPA-friendly) ============
# مهم: حتى لو فتح الزائر /i/ahmed-noor بدون /index.html، يشتغل
RewriteEngine On
RewriteBase /

# لو الملف موجود (file أو directory) اتركه
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# لكل المسارات الأخرى، ارجع لـ index.html (لكن index.html الخاص بـ static export)
# أو لـ trailing slash variant
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]+$ [NC]
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1/ [L,R=301]

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

# ============ Browser Caching ============
<IfModule mod_expires.c>
  ExpiresActive On
  # HTML
  ExpiresByType text/html "access plus 1 hour"
  # CSS, JS
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"
  # Images
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
  # Fonts
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>

# ============ Security Headers ============
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>

# ============ UTF-8 Encoding ============
AddDefaultCharset UTF-8

# ============ Disable directory listing ============
Options -Indexes

# ============ Custom Error Pages ============
ErrorDocument 404 /404.html

# ============ Cache-Control for static assets ============
<IfModule mod_headers.c>
  <FilesMatch "\.(css|js|woff2?|ttf|otf|eot|svg|png|jpg|jpeg|gif|webp|ico)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.(html)$">
    Header set Cache-Control "public, max-age=3600, must-revalidate"
  </FilesMatch>
</IfModule>

# ============ GZIP types ============
<IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_item_include file \.html$
  mod_gzip_item_include file \.css$
  mod_gzip_item_include file \.js$
  mod_gzip_item_include file \.svg$
</IfModule>