# =========================================================
# VHXCORE CMS — .htaccess
# =========================================================

# Кодировка
AddDefaultCharset UTF-8

# Главный файл
DirectoryIndex index.php index.html

# Отключаем листинг директорий
Options -Indexes

# Следуем симлинкам
Options +FollowSymLinks

# =========================================================
# ЗАЩИТА ФАЙЛОВ
# =========================================================

# Служебные файлы
<FilesMatch "^(\.htaccess|\.htpasswd|\.gitignore|\.env|composer\.(json|lock)|package\.(json|lock)|README\.md|CHANGELOG\.md)$">
    Require all denied
</FilesMatch>

# Конфиг
<Files "config.php">
    Require all denied
</Files>

# Lock-файл установки
<Files "installed.lock">
    Require all denied
</Files>

# Скрытые файлы и папки
<FilesMatch "^\.">
    Require all denied
</FilesMatch>

# =========================================================
# БЕЗОПАСНЫЕ ЗАГОЛОВКИ
# =========================================================
<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 unset X-Powered-By
</IfModule>

# =========================================================
# КЕШ СТАТИКИ
# =========================================================
<IfModule mod_expires.c>
    ExpiresActive On

    ExpiresByType image/jpeg        "access plus 30 days"
    ExpiresByType image/png         "access plus 30 days"
    ExpiresByType image/gif         "access plus 30 days"
    ExpiresByType image/webp        "access plus 30 days"
    ExpiresByType image/svg+xml     "access plus 30 days"
    ExpiresByType image/x-icon      "access plus 30 days"

    ExpiresByType text/css          "access plus 7 days"
    ExpiresByType application/javascript "access plus 7 days"

    ExpiresByType font/woff         "access plus 30 days"
    ExpiresByType font/woff2        "access plus 30 days"
</IfModule>
# Не трогать реально существующие файлы и папки
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# =========================================================
# КРАСИВЫЕ URL
# =========================================================
<IfModule mod_rewrite.c>
    RewriteEngine On

    # --- Авторизация / регистрация ---
    RewriteRule ^login/?$            index.php?action=login    [L,QSA]
    RewriteRule ^register/?$         index.php?action=register [L,QSA]
    RewriteRule ^logout/?$           logout.php                [L,QSA]

    # --- Профиль ---
    RewriteRule ^profile/?$          profile.php               [L,QSA]
    RewriteRule ^profile/([0-9]+)/?$ profile.php?id=$1         [L,QSA]

    # --- Админка ---
    RewriteRule ^admin/?$                       admin/index.php         [L,QSA]
    RewriteRule ^admin/forum/?$                 admin/forum/index.php   [L,QSA]
    RewriteRule ^admin/forum/sections/?$        admin/forum/sections.php [L,QSA]
    RewriteRule ^admin/forum/section/create/?$  admin/forum/edit-section.php [L,QSA]
    RewriteRule ^admin/forum/section/edit/([0-9]+)/?$ admin/forum/edit-section.php?id=$1 [L,QSA]
# Загрузка файла (короткий URL)
RewriteRule ^downloads/upload/?$ /downloads/admin/edit-file.php [L,QSA]
    RewriteRule ^admin/downloads/?$             admin/downloads/index.php [L,QSA]
    RewriteRule ^admin/downloads/category/([0-9]+)/?$ admin/downloads/category.php?id=$1 [L,QSA]
    RewriteRule ^admin/downloads/file/edit/([0-9]+)/?$ admin/downloads/edit-file.php?id=$1 [L,QSA]
    RewriteRule ^admin/downloads/file/upload/?$ admin/downloads/edit-file.php [L,QSA]
    RewriteRule ^admin/news/?$                  admin/news/index.php     [L,QSA]
    RewriteRule ^admin/news/create/?$           admin/edit.php           [L,QSA]
    RewriteRule ^admin/news/edit/([0-9]+)/?$    admin/edit.php?id=$1     [L,QSA]

    RewriteRule ^admin/users/?$                 admin/users.php          [L,QSA]
    RewriteRule ^admin/settings/?$              admin/setting.php       [L,QSA]

    # --- Форум (публичный) ---
    RewriteRule ^forum/?$                       forum/index.php          [L,QSA]
    RewriteRule ^forum/section/([0-9]+)/?$      forum/section.php?id=$1  [L,QSA]
    RewriteRule ^forum/topic/([0-9]+)/?$        forum/topic.php?id=$1    [L,QSA]
    RewriteRule ^forum/topic/create/([0-9]+)/?$ forum/create-topic.php?section=$1 [L,QSA]
    RewriteRule ^forum/topic/edit/([0-9]+)/?$   forum/edit-topic.php?id=$1 [L,QSA]
    RewriteRule ^forum/post/edit/([0-9]+)/?$    forum/edit-post.php?id=$1 [L,QSA]
RewriteRule ^forum/new-topic/?$ forum/new-topic.php [L,QSA]
RewriteRule ^create/?$ /forum/admin/edit.php [L,QSA]
# --- Загрузки (публичный) ---
    RewriteRule ^downloads/?$                   downloads/index.php       [L,QSA]
    RewriteRule ^downloads/category/([0-9]+)/?$ downloads/category.php?id=$1 [L,QSA]
    RewriteRule ^downloads/file/([0-9]+)/?$     downloads/file.php?id=$1  [L,QSA]

    # --- Новости (публичный) ---
    RewriteRule ^news/?$                        news.php            [L,QSA]
    RewriteRule ^news/([0-9]+)/?$               news.php?id=$1            [L,QSA]
</IfModule>
# Лицензия
<FilesMatch "^\.vhl(\.sig)?$">
    Require all denied
</FilesMatch>

# Конфиг
<FilesMatch "^config\.php$">
    Require all denied
</FilesMatch>

# =========================================================
# СЖАТИЕ
# =========================================================
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# =========================================================
# MIME
# =========================================================
<IfModule mod_mime.c>
    AddType image/webp              .webp
    AddType image/svg+xml           .svg
    AddType font/woff               .woff
    AddType font/woff2              .woff2
</IfModule>