RewriteEngine On

# Redirecionar para HTTPS se necessário (descomente se quiser usar)
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteRule ^venuegame$ index.php [L,QSA]

RewriteBase /

# Specific Callback Route for Gamblly
RewriteRule ^callback/?$ callback/gamblly.php [QSA,L]
RewriteRule ^api/game/callback/?$ callback/gamblly.php [QSA,L]
RewriteRule ^api/game/callback\.php$ callback/gamblly.php [QSA,L]

# Regras para a API
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api/v1/api.php [QSA,L]

RewriteRule  ^playfiver/webhook		callback/gamblly.php	 		 [NC,L]
RewriteRule  ^gamblly/webhook		callback/gamblly.php	 		 [NC,L]


# Se o arquivo ou diretório não existir, redirecione para o index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

# Regras adicionais para segurança e configuração
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
</IfModule>

# ----------------------------------------------------------------------
# | Anti- Clickjacking                                                  |
# ----------------------------------------------------------------------
<IfModule mod_headers.c>
    <FilesMatch "\.(html|htm)$">
        Header set X-Frame-Options "DENY"
    </FilesMatch>
</IfModule>

# ----------------------------------------------------------------------
# | Negando acesso aos diretórios                                       |
# ---------------------------------------------------------------------
<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

# ----------------------------------------------------------------------
# | Bloqueando arquivos sensíveis                                       |
# ----------------------------------------------------------------------
<FilesMatch "(^#.*#|\.(bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$">
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
    </IfModule>
</FilesMatch>

# ----------------------------------------------------------------------
# | Block secrets, installer data and maintenance tools (added by installer)
# ----------------------------------------------------------------------
<FilesMatch "^\.(env|git|htpasswd)|\.(env|example|template|lock|md|lockb)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>
RewriteRule ^(_tools|install/sql)(/|$) - [F,L]

# bw-nocache: always revalidate the app JS/CSS (304 if unchanged) so updates are picked up
<IfModule mod_headers.c>
    <FilesMatch "\.(js|css)$">
        Header set Cache-Control "no-cache, must-revalidate"
    </FilesMatch>
</IfModule>
