# ====================================================================
#  Củ Hành - Apache (.htaccess ở thư mục gốc, chạy trực tiếp ngoài web root)
#  Nếu chạy trong thư mục con của XAMPP (http://localhost/cuhanh/),
#  bỏ dấu # ở dòng RewriteBase bên dưới.
# ====================================================================
Options -Indexes -MultiViews
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    # RewriteBase /cuhanh/

    # 1) Chặn truy cập trực tiếp vào thư mục chứa mã nguồn và dữ liệu
    RewriteRule ^(app|core|config|database|lang|views|storage|vendor|deploy|bin)(/|$) - [F,L,NC]

    # 2) Chặn file ẩn (.env, .git, .htaccess...) và các loại file nhạy cảm
    RewriteRule (^|/)\.(?!well-known) - [F,L]
    RewriteRule \.(sql|log|md|lock|json|ini|sh|bak|env|dist)$ - [F,L,NC]

    # 3) Mọi request không phải file/thư mục thật thì chuyển cho index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

# Chỉ index.php được phép chạy trực tiếp
<FilesMatch "\.php$">
    Require all denied
</FilesMatch>
<Files "index.php">
    Require all granted
</Files>

<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"
</IfModule>

# Phụ đề WebVTT phải có kiểu text/vtt thì trình duyệt mới nạp
<IfModule mod_mime.c>
    AddType text/vtt .vtt
</IfModule>

# Nén và cache file tĩnh
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript image/svg+xml text/vtt application/json
</IfModule>
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 30 days"
    ExpiresByType application/javascript "access plus 30 days"
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType image/svg+xml "access plus 30 days"
</IfModule>
