ns inherit
# Disable directory browsing
Options All -Indexes

# Cho phép file bot.php truy cập qua Cloudflare
<Files "bot.php">
    Require all granted
</Files>

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Nếu có mod_cloudflare, xử lý IP đúng
    <IfModule mod_cloudflare.c>
        CloudFlareRemoteIPHeader CF-Connecting-IP
    </IfModule>

    # Nếu không có mod_cloudflare, fallback dùng X-Forwarded-For
    SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
    RequestHeader set X-Real-IP %{REMOTE_ADDR}s env=forwarded
    RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s env=forwarded

    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{env:HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Bỏ qua bot.php để không rewrite về index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/bot\.php$
    RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
ServerSignature Off

# BLOCK ảnh nếu không phải từ domain cụ thể
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?k93hax\.xyz/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?api\.k93hax\.xyz/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

# Bảo vệ .env
<Files .env>
    Order allow,deny
</Files>

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^\.env$ "https\:\/\/k93hax\.xyz\/" [R=301,L]
RewriteRule ^cpanel$ "https\:\/\/k93hax\.xyz\/" [R=301,L]

# PHP cấu hình của cPanel
<IfModule mime_module>
    AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
