# AetherOS :: AetherDrift
# Apache 配置 — 安全 + URL 重写

# 启用重写引擎
RewriteEngine On

# 强制 HTTPS（如果可用）
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# 禁止访问敏感文件
<FilesMatch "\.(env|lock|sql|log|md|htaccess|json|yml)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# 禁止直接访问 config 和 memory 目录
<IfModule mod_rewrite.c>
    RewriteRule ^config/ - [F,L]
    RewriteRule ^memory/ - [F,L]
</IfModule>

<IfModule mod_php>
    php_flag display_errors off
    php_value max_execution_time 60
    php_value upload_max_filesize 5M
    php_value post_max_size 8M
    php_value session.cookie_httponly 1
    php_value session.cookie_samesite "Strict"
    php_value session.use_only_cookies 1
</IfModule>

# 安全头
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
    Header set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://fonts.googleapis.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self' ws:;"
</IfModule>

# 静态资源缓存
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css      "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType image/png      "access plus 1 month"
    ExpiresByType image/jpeg     "access plus 1 month"
    ExpiresByType image/svg+xml   "access plus 1 month"
</IfModule>

# 禁止目录浏览
Options -Indexes

# 允许 .php 处理
AddType application/x-httpd-php .php
