Options -MultiViews
RewriteEngine On
RewriteBase /

# =========================
# REDIRECIONAMENTOS SIMPLES
# =========================

# /login -> /signin
RewriteRule ^login/?$ signin [R=302,L]

# /logout -> /signout
RewriteRule ^logout/?$ signout [R=301,L]

# =========================
# ROTAS DIRETAS
# =========================
# =========================
# CAPTAÇÃO (LANDING PAGES)
# =========================
RewriteRule ^associados/?$ seja-associado.php [L]
RewriteRule ^seja-associado/?$ seja-associado.php [L]
RewriteRule ^anunciantes/?$ seja-anunciante.php [L]
RewriteRule ^seja-anunciante/?$ seja-anunciante.php [L]
RewriteRule ^ideias-de-campanha/?$ ideias-de-campanha.php [L]

RewriteRule ^index/?$ index.php [L]
RewriteRule ^error/?$ error.php [L]
RewriteRule ^offline/?$ offline.php [L]
RewriteRule ^signin/?$ signin.php [L]
RewriteRule ^signup/?$ signup.php [L]
RewriteRule ^signout/?$ signout.php [L]
RewriteRule ^forgot/?$ forgot.php [L]
RewriteRule ^profile/?$ profile.php [L]
RewriteRule ^reset/?$ reset.php [L]
RewriteRule ^activate/?$ activate.php [L]
RewriteRule ^verify/?$ verify.php [L]
RewriteRule ^private/?$ private.php [L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]

# =========================
# ROTAS ESPECÍFICAS
# =========================

RewriteRule ^deal/([0-9]+)/([a-zA-Z0-9_-]+)$ index.php?deal_id=$1&slug=$2&%{QUERY_STRING} [L,QSA]

RewriteRule ^location/([a-zA-Z0-9_-]+)$ single-location.php?slug=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^user/([a-zA-Z0-9_-]+)$ single-user.php?slug=$1&%{QUERY_STRING} [L,QSA]
# A URL de pagamento é gerada pelo JS no formato /pay/{id}/?freq=...
# Aceita (opcionalmente) a barra final para evitar falhas de rota
RewriteRule ^pay/([a-zA-Z0-9_-]+)/?$ pay.php?id=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^success/([a-zA-Z0-9_-]+)/?$ success.php?id=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^cancel/([a-zA-Z0-9_-]+)/?$ cancel.php?id=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^redirect/([^/]+)$ redirect.php?id=$1&%{QUERY_STRING} [L,QSA]

# =========================
# PÁGINA PÚBLICA DA LOJA
# =========================
# /store/slug-da-loja  -> store.php?slug=slug-da-loja

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^store/([a-zA-Z0-9_-]+)$ store.php?slug=$1&%{QUERY_STRING} [L,QSA]

# =========================
# FALLBACK GENÉRICO (PÁGINAS CMS)
# =========================
# Qualquer outra slug sem arquivo/diretório real cai no single-page.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ single-page.php?slug=$1&%{QUERY_STRING} [L,QSA]

# =========================
# HEADERS E PHP
# =========================
<IfModule mod_headers.c>
  Header set Permissions-Policy "geolocation=(self)"
</IfModule>

<IfModule mod_php7.c>
  php_value auto_prepend_file /home/ndmidia/public_html/conecta.ndmidia.com.br/core_bootstrap.php
</IfModule>
<IfModule mod_php8.c>
  php_value auto_prepend_file /home/ndmidia/public_html/conecta.ndmidia.com.br/core_bootstrap.php
</IfModule>

# BEGIN cPanel-generated php ini directives, do not edit
<IfModule php8_module>
   php_value auto_prepend_file "/home/ndmidia/public_html/conecta.ndmidia.com.br/core_bootstrap.php"
</IfModule>
<IfModule lsapi_module>
   php_value auto_prepend_file "/home/ndmidia/public_html/conecta.ndmidia.com.br/core_bootstrap.php"
</IfModule>
# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit
# Defina o pacote “ea-php82” como a linguagem padrão de programação “PHP”.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
