# فعال کردن خطایابی
php_flag display_errors on
php_value error_reporting E_ALL

# جلوگیری از لیست کردن پوشه‌ها
Options -Indexes

# محافظت از فایل‌های مهم
<FilesMatch "\.(sql|log|lock|env|htaccess)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# ریدایرکت به فایل خطا
ErrorDocument 500 /NikanCRM/error.php
ErrorDocument 404 /NikanCRM/error.php
ErrorDocument 403 /NikanCRM/error.php

# فعال‌سازی rewrite
RewriteEngine On
RewriteBase /NikanCRM/

# --- بخش مهم: اجازه دسترسی مستقیم به admin_panel.php ---
RewriteRule ^admin_panel\.php$ - [L]

# --- بخش مهم: اجازه دسترسی به فایل‌های استاتیک ---
# 1. اجازه دسترسی به فایل‌های تصاویر و رسانه‌ها
<FilesMatch "\.(jpg|jpeg|png|gif|bmp|ico|svg|webp|avif)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

# 2. اجازه دسترسی به فایل‌های CSS، JS و فونت‌ها
<FilesMatch "\.(css|js|woff|woff2|ttf|eot|otf)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

# 3. تنظیمات کش برای تصاویر (اختیاری - برای بهبود سرعت)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

# اجازه دسترسی به فایل‌های خاص در templates
RewriteCond %{REQUEST_URI} ^/NikanCRM/templates/
RewriteRule (buyer_dashboard\.php|user_dashboard\.php|buyer_register_form\.php|my_buyers_list\.php|other_buyers_list\.php|test\.php|messages_user\.php)$ - [L]

# بلاک کردن بقیه فایل‌ها در templates
RewriteCond %{REQUEST_URI} ^/NikanCRM/templates/
RewriteRule .* - [F,L]

# اگر فایل یا پوشه فیزیکی وجود دارد، مستقیم سرویس دهی کن
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(jpg|jpeg|png|gif|bmp|ico|svg|webp|avif|css|js|woff|woff2|ttf|eot|otf)$ - [L]

# اگر فایل یا پوشه وجود ندارد، به index برو
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]