# ============================================================
# OrozDesign Multimedia - Apache .htaccess
# ============================================================

RewriteEngine On
RewriteBase /

# 404 Personalizado (SOP-SEO-Local.md Sección 12)
ErrorDocument 404 /404.php

# Sitemap XML dinámico
RewriteRule ^sitemap\.xml$ sitemap.php [L,QSA]
RewriteRule ^robots\.txt$ robots.txt [L]

# Map /sitefloox/vsl.php to /vsl.php
RewriteRule ^sitefloox/vsl\.php$ vsl.php [L,QSA]

# Map /sitefloox/last-call.php/ to /last-call.php
RewriteRule ^sitefloox/last-call\.php/?(.*)$ last-call.php/$1 [L,QSA]

# Service Area Pages (SAPs) Routing
# /locations/ -> locations.php
# /locations/dallas-tx/ -> locations.php?city_slug=dallas-tx
RewriteRule ^locations/?$ locations.php [L,QSA]
RewriteRule ^locations/([a-zA-Z0-9_-]+)/?$ locations.php?city_slug=$1 [L,QSA]

# Evergreen Hubs Routing
RewriteRule ^faq/?$ faq.php [L,QSA]
RewriteRule ^reviews/?$ reviews.php [L,QSA]
RewriteRule ^testimonios/?$ reviews.php [L,QSA]
RewriteRule ^free-estimate/?$ free-estimate.php [L,QSA]
RewriteRule ^cotizacion/?$ free-estimate.php [L,QSA]

# URLs limpias sin extensión .php (SOP-SEO-Local.md Sección 1.3)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Excluir archivos y directorios reales
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# ============================================================
# COMPRESIÓN GZIP (Core Web Vitals - LCP)
# ============================================================
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript application/json application/xml
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# ============================================================
# CACHÉ DEL NAVEGADOR (Core Web Vitals)
# ============================================================
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/json "access plus 1 week"
</IfModule>

# ============================================================
# CABECERAS DE SEGURIDAD (SOP-SEO-Local.md Sección 1.3)
# ============================================================
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
