# ---- سایت استاتیک Next.js روی سی‌پنل (Apache) ----
DirectoryIndex index.html index.php
Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On

# اعتبارسنجی SSL (AutoSSL) به این مسیر روی http نیاز دارد؛ ریدایرکت نشود
RewriteRule ^\.well-known/ - [L]

# ریدایرکت به https (بعد از صدور SSL فعال می‌شود)
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# www -> بدون www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
</IfModule>

# ---- پنل مدیریت: صفحات و محتوای پویا از طریق dynamic.php (اگر محتوایی نباشد همان صفحه استاتیک نمایش داده می‌شود) ----
<IfModule mod_rewrite.c>
RewriteRule ^sitemap-cms\.xml$ /dynamic.php?sitemap=1 [L]
RewriteRule ^search-cms\.json$ /dynamic.php?searchindex=1 [L]
RewriteRule ^((?:en/|ru/)?(?:about|accommodations|experiences|gallery|blog|events|handicraft-shop|about-us|stay|things-to-do|photo-gallery|travel-blog|events-calendar|craft-shop|o-nas|prozhivanie|vpechatleniya|galereya|blog-helile|sobytiya|remesla)(?:/[^/.]+)?)/?$ /dynamic.php?p=$1 [L,QSA]
</IfModule>

ErrorDocument 404 /404.html

# فشرده‌سازی
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml text/plain application/xml
</IfModule>

# کش فایل‌های ثابت (نام فایل‌های _next/static شامل هش است)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType text/html "access plus 0 seconds"
</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"
</IfModule>

# فایل وضعیت دیپلوی خودکار از وب قابل دسترس نباشد
<Files ".ftp-deploy-sync-state.json">
Require all denied
</Files>
