# ============================================================
#  رزومهٔ شخصی — تنظیمات Apache
#  نیازمند: AllowOverride All (در هاست‌های اشتراکی cPanel معمولاً فعال است)
# ============================================================

Options -Indexes
DirectoryIndex index.php index.html

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

# نکته: خاموش‌کردن موتور PHP در این فایل باعث می‌شود خود سایت هم کار نکند.
# محافظت از فایل‌های آپلودشده در storage/uploads/.htaccess انجام می‌شود.

# ---- مسدود کردن فایل‌های حساس ----
<FilesMatch "^\.|composer\.(json|lock)|package(-lock)?\.json|\.sqlite$|\.lock$|\.done$|\.md$">
    Require all denied
</FilesMatch>

# ---- آدرس‌های تمیز ----
<IfModule mod_rewrite.c>
    RewriteEngine On
    # Preserve an Apache Alias prefix through internal rewrites.
    RewriteRule ^ - [E=REZUME_BASE:%{CONTEXT_PREFIX}]

    # اگر سایت را در زیرپوشه نصب کرده‌اید (مثلاً public_html/rezume)،
    # خط زیر را از کامنت خارج کنید و نام پوشه را بنویسید:
    # RewriteBase /rezume/

    # اجباری‌کردن HTTPS (پس از نصب SSL فعال کنید):
    # RewriteCond %{HTTPS} off
    # RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

    # حذف www (اختیاری):
    # RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    # RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

    # robots must remain dynamic even though a static fallback exists.
    RewriteRule ^robots\.txt$ robots.php [L]

    # درخواست‌هایی که به فایل یا پوشهٔ واقعی اشاره دارند، مستقیم سرو می‌شوند
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # فایل‌های پویا
    RewriteRule ^sitemap\.xml$            sitemap.php     [L,QSA]
    RewriteRule ^robots\.txt$             robots.php      [L]

    # صفحات سایت
    RewriteRule ^work/?$                  work.php        [L,QSA]
    RewriteRule ^contact/?$               contact.php     [L,QSA]

    # وبلاگ
    RewriteRule ^blog/?$                          blog.php              [L,QSA]
    RewriteRule ^blog/page/([0-9]+)/?$            blog.php?p=$1         [L,QSA]
    RewriteRule ^blog/cat/([^/]+)/?$              blog.php?cat=$1       [L,QSA]
    RewriteRule ^blog/cat/([^/]+)/page/([0-9]+)/?$ blog.php?cat=$1&p=$2 [L,QSA]
    RewriteRule ^page/([^/]+)/?$ page.php?slug=$1 [L,QSA]
    RewriteRule ^post/([^/]+)/?$                  post.php?slug=$1      [L,QSA]

    # پنل مدیریت
    RewriteRule ^admin/?$                 admin/index.php [L]
    RewriteCond %{REQUEST_FILENAME} ^(.+?)/?$
    RewriteCond %1.php -f
    RewriteRule ^admin/([a-z0-9_-]+)/?$   admin/$1.php    [L,QSA]
    RewriteRule ^admin/.*$ admin/notfound.php [L]

    # هر آدرس ناشناخته → صفحهٔ خطا (کد وضعیت ۴۰۴ در خود فایل تنظیم می‌شود)
    RewriteRule ^.*$ 404.php [L]
</IfModule>

# پشتیبان برای زمانی که mod_rewrite فعال نیست
ErrorDocument 404 /404.php
ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 405 /405.php
ErrorDocument 408 /408.php
ErrorDocument 413 /413.php
ErrorDocument 429 /429.php
ErrorDocument 500 /500.php
ErrorDocument 502 /502.php
ErrorDocument 503 /503.php
ErrorDocument 504 /504.php

# ---- کش مرورگر ----
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css               "access plus 30 days"
    ExpiresByType application/javascript "access plus 30 days"
    ExpiresByType font/woff2             "access plus 1 year"
    ExpiresByType image/jpeg             "access plus 6 months"
    ExpiresByType image/png              "access plus 6 months"
    ExpiresByType image/webp             "access plus 6 months"
    ExpiresByType image/svg+xml          "access plus 6 months"
    ExpiresByType image/x-icon           "access plus 1 year"
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/javascript
    AddOutputFilterByType DEFLATE application/json application/xml image/svg+xml font/woff2
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(css|js|woff2|svg|png|jpe?g|webp|ico)$">
        Header set Cache-Control "public, max-age=2592000"
    </FilesMatch>
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
