# ============================================================
# 圣巧依官网 - public/.htaccess（唯一配置）
# ============================================================

# ── sitemap.xml 白名单（必须放在最前面）──
<Files "sitemap.xml">
    Require all granted
</Files>

# ── 禁止直接访问敏感文件 ──
<FilesMatch "\.(env|git|svn|htaccess|htpasswd|ini|log|bak|old|swp|dist|save|sql|zip|yml|md|lock)$">
    Require all denied
</FilesMatch>
<FilesMatch "^(composer\.json|composer\.lock|package\.json|package-lock\.json|README|CHANGELOG|LICENSE|Makefile|config\.php)$">
    Require all denied
</FilesMatch>

# ── 禁止列出目录 ──
Options -Indexes

# ── 安全响应头 ──
<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    Header always set Permissions-Policy "geolocation=(), microphone=(), camera=(), payment=(), usb=()"
</IfModule>

# ── 静态资源缓存 ──
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
</IfModule>

# ── Gzip 压缩 ──
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json application/xml image/svg+xml
</IfModule>

# ── URL 重写：非静态文件全部走 index.php ──
<IfModule mod_rewrite.c>
    RewriteEngine On

# 如果请求的是真实存在的文件或目录，直接返回
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # 其余所有请求交给 index.php（应用自己处理路由）
    RewriteRule ^ index.php [L,QSA]
</IfModule>
