# ============================================
# COMPRESSION
# ============================================
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# ============================================
# CACHING
# ============================================
<IfModule mod_expires.c>
    ExpiresActive On
    
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
    
    ExpiresByType text/html "access plus 1 hour"
    
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType application/xml "access plus 1 day"
    ExpiresByType text/xml "access plus 1 day"
</IfModule>

# ============================================
# SECURITY HEADERS
# ============================================
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set X-Frame-Options "SAMEORIGIN"
    
    # Скрываем информацию о сервере
    Header unset Server
    Header unset X-Powered-By
    Header unset X-AspNet-Version
    
    # Кеш для статики
    <FilesMatch "\.(ico|jpg|jpeg|png|gif|webp|svg|css|js|woff|woff2)$">
        Header set Cache-Control "public, max-age=2592000"
    </FilesMatch>
</IfModule>

# ============================================
# BOT BLOCKING
# ============================================
SetEnvIfNoCase User-Agent "ia_archiver" BlockBot
SetEnvIfNoCase User-Agent "archive.org_bot" BlockBot
SetEnvIfNoCase User-Agent "Wayback" BlockBot
SetEnvIfNoCase User-Agent "WaybackMachine" BlockBot
SetEnvIfNoCase User-Agent "WebCite" BlockBot
SetEnvIfNoCase User-Agent "CCBot" BlockBot
SetEnvIfNoCase User-Agent "Common Crawl" BlockBot
SetEnvIfNoCase User-Agent "AhrefsBot" BlockBot
SetEnvIfNoCase User-Agent "SemrushBot" BlockBot
SetEnvIfNoCase User-Agent "MJ12bot" BlockBot
SetEnvIfNoCase User-Agent "DotBot" BlockBot

<RequireAll>
    Require all granted
    Require not env BlockBot
</RequireAll>

# ============================================
# FILE PROTECTION
# ============================================
# Скрытые файлы
<Files ~ "^\.">
    Require all denied
</Files>

# Опасные расширения
<FilesMatch "\.(bak|backup|old|orig|save|swp|tmp|log|sql|zip|tar|gz|rar|env|ini|conf|config)$">
    Require all denied
</FilesMatch>

# Защита wp-config и подобных (если есть)
<Files "wp-config.php">
    Require all denied
</Files>

# ============================================
# DIRECTORY PROTECTION
# ============================================
RedirectMatch 403 ^/\.
RedirectMatch 403 ^/admin/?
RedirectMatch 403 ^/private/?
RedirectMatch 403 ^/backup/?
RedirectMatch 403 ^/logs/?
RedirectMatch 403 ^/temp/?
RedirectMatch 403 ^/config/?

# ============================================
# REWRITES
# ============================================
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove www (опционально — раскомментируй если нужно)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Remove trailing slash (кроме директорий)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]

# Remove query string from homepage
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^$ /? [R=301,L]

# ============================================
# PLAY REDIRECTS TO TDS (с динамическим subid)
# ============================================
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# /play/ (без бренда) → принудительно play
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^play/?$ https://reg2dep.click/play/$1?subid=%1 [R=302,L,QSA]

# /play/brandname → стандартная логика
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^play/([a-zA-Z0-9_-]+)/?$ https://reg2dep.click/play/$1?subid=%1 [R=302,L,QSA]

# ============================================
# 404 REDIRECT TO HOMEPAGE
# ============================================
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [R=301,L]

# ============================================
# OPTIONS
# ============================================
Options -Indexes -MultiViews +FollowSymLinks
ServerSignature Off
<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 43.133.36.219
deny from 43.128.87.4
deny from 43.128.89.111
deny from 43.133.41.88
deny from 43.134.1.185
deny from 43.134.53.242
deny from 43.134.104.17
deny from 43.134.111.0/24
deny from 43.134.121.208
deny from 43.134.127.70
deny from 43.134.162.36
deny from 43.134.178.104
deny from 43.134.187.251
deny from 43.156.34.42
deny from 43.156.50.197
deny from 43.156.168.214
deny from 43.156.225.86
deny from 43.156.228.27
deny from 43.156.249.28
deny from 43.159.46.41
deny from 43.159.57.144
deny from 43.159.58.77
deny from 43.160.225.169
deny from 43.163.4.179
deny from 47.82.8.94
deny from 47.82.15.232
deny from 101.32.128.113
deny from 101.32.244.128
deny from 119.28.100.147
deny from 124.156.206.78
deny from 129.226.146.42
deny from 129.226.193.122
deny from 129.226.209.117
deny from 129.226.217.17
deny from 146.70.199.195
deny from 202.76.134.192
deny from 202.76.164.214
