# ===================================================================
#  amir-saleh.com — .htaccess (PHP 8.4)
# ===================================================================
Options -Indexes
ServerSignature Off

RewriteEngine On
RewriteBase /

# ---------- منع الوصول للملفات والمجلدات الحساسة ----------
RewriteRule ^(private|include|database)(/|$) - [F,L]
RewriteRule (^|/)\.(?!well-known/) - [F,L]
<FilesMatch "(\.(sql|log|bak|old|orig|ini|sh|md|dist)|error_log|php_errors\.log)$">
    Require all denied
</FilesMatch>

# ---------- توحيد الدومين وHTTPS ----------
# كل الأسماء القديمة -> https://amir-saleh.com
RewriteCond %{HTTP_HOST} ^(www\.)?amir-saleh\.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.amir-saleh\.com$ [NC]
RewriteRule ^(.*)$ https://amir-saleh.com/$1 [L,R=301]

# أي طلب http -> https (يعمل أيضاً مع دومين التجربة new2)
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

# ---------- روابط الموقع ----------
RewriteRule ^v/([^/]+)/(.*)$ watch.php?v=$1 [L,QSA]
RewriteRule ^v/([^/]+)/?$ watch.php?v=$1 [L,QSA]

RewriteRule ^sitemap-media\.xml$ sitemap-media.php [L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^sitemap-video\.xml$ sitemap-video.php [L]
RewriteRule ^sitemap-pages\.xml$ sitemap-pages.php [L]

# ---------- المسارات الاحترافية ----------
# أي رابط ليس ملفاً أو مجلداً حقيقياً يذهب إلى index.php (include/router.php يحدد الصفحة)
# أمثلة: /consultations  /consultation/3527/عنوان  /article/120/عنوان  /contact  /search?q=...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]

# ---------- رؤوس أمان ----------
<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"
    Header always set Strict-Transport-Security "max-age=31536000"
    Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 12 hour"

# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"

# Your document html
  ExpiresByType text/html                 "access plus 1 hour"

# Data
  ExpiresByType application/json          "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType text/xml                  "access plus 0 seconds"

# Feed
  ExpiresByType application/atom+xml      "access plus 1 hour"
  ExpiresByType application/rss+xml       "access plus 1 hour"

# Favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 week"

# Media: images, video, audio
  ExpiresByType audio/ogg                 "access plus 1 week"
  ExpiresByType image/gif                 "access plus 1 week"
  ExpiresByType image/jpg                 "access plus 1 week"
  ExpiresByType image/jpeg                "access plus 1 week"
  ExpiresByType image/png                 "access plus 1 week"
  ExpiresByType video/mp4                 "access plus 1 week"
  ExpiresByType video/ogg                 "access plus 1 week"
  ExpiresByType video/webm                "access plus 1 week"

# HTC files  (css3pie)
  ExpiresByType text/x-component          "access plus 1 week"

# Webfonts
  ExpiresByType application/vnd.ms-fontobject "access plus 1 week"
  ExpiresByType application/x-font-ttf    "access plus 1 week"
  ExpiresByType application/x-font-woff   "access plus 1 week"
  ExpiresByType font/opentype             "access plus 1 week"
  ExpiresByType image/svg+xml             "access plus 1 week"

# CSS and JavaScript
  ExpiresByType application/javascript    "access plus 1 week"
  ExpiresByType text/css                  "access plus 1 week"

</IfModule>


# php -- BEGIN cPanel-generated handler, do not edit
# الأفضل اختيار PHP 8.4 من cPanel > MultiPHP Manager (سيكتب هذا الجزء تلقائياً)
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php84___lsphp .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
