# Calor Invierno – Serverregeln (Apache / LiteSpeed)
# 29.11.2026 : alle Adressen der Seiten enden auf .html (/aviso-legal.html, /producto/<slug>.html …) ; die alten Formen (/aviso-legal/,
# /producto/<slug>/, /seguimiento-pedido/?nr=…&t=…) antworten mit 301. Die Umleitungen stehen VOR dem Ausliefern der Dateien : alte Ordner
# auf dem Server stören nicht.
DirectoryIndex index.html index.php
ErrorDocument 404 /404.html
ErrorDocument 403 /404.html
Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
# private Ordner und Dateien
RewriteRule ^(_daten|_werkzeuge|api/_lib)(/|$) - [F,L]
RewriteRule \.(md|json|bat|py|lock|sqlite|ini)$ - [F,L,NC]
# HTTPS und Adresse ohne www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# Feed, Robots, Sitemap
RewriteRule ^catalogo-google\.xml$ api/feed.php?was=feed [L,QSA]
RewriteRule ^robots\.txt$ api/feed.php?was=robots [L]
RewriteRule ^sitemap\.xml$ api/feed.php?was=sitemap [L]

# ---- 1. alte Adressen mit Angaben hinter « ? » → Angaben im Dateinamen (301 ; nur die Anfrage des Browsers, nie die interne Umschreibung)
RewriteCond %{THE_REQUEST} \s/+buscar(?:/|/index\.html|\.html)?\?(?:[^\s]*&)?q=([^&\s]+)
RewriteRule ^buscar(?:/|/index\.html|\.html)?$ /buscar/%1.html? [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+pedido-recibido(?:/|/index\.html|\.html)?\?nr=([A-Za-z0-9-]+)&t=([A-Za-z0-9]+)&rueckkehr=1
RewriteRule ^pedido-recibido(?:/|/index\.html|\.html)?$ /pedido-recibido/%1/%2/tarjeta.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+pedido-recibido(?:/|/index\.html|\.html)?\?nr=([A-Za-z0-9-]+)&t=([A-Za-z0-9]+)&bizum=1&cancelado=1
RewriteRule ^pedido-recibido(?:/|/index\.html|\.html)?$ /pedido-recibido/%1/%2/bizum-cancelado.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+pedido-recibido(?:/|/index\.html|\.html)?\?nr=([A-Za-z0-9-]+)&t=([A-Za-z0-9]+)&bizum=1
RewriteRule ^pedido-recibido(?:/|/index\.html|\.html)?$ /pedido-recibido/%1/%2/bizum.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+pedido-recibido(?:/|/index\.html|\.html)?\?nr=([A-Za-z0-9-]+)&t=([A-Za-z0-9]+)
RewriteRule ^pedido-recibido(?:/|/index\.html|\.html)?$ /pedido-recibido/%1/%2.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+seguimiento-pedido(?:/|/index\.html|\.html)?\?nr=([A-Za-z0-9-]+)&t=([A-Za-z0-9]+)
RewriteRule ^seguimiento-pedido(?:/|/index\.html|\.html)?$ /seguimiento-pedido/%1/%2.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+carrito/recordatorio(?:/|/index\.html|\.html)?\?e=([A-Za-z0-9]+)&t=([A-Za-z0-9]+)&aus=1
RewriteRule ^carrito/recordatorio(?:/|/index\.html|\.html)?$ /carrito/recordatorio/%1/%2/baja.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+carrito/recordatorio(?:/|/index\.html|\.html)?\?e=([A-Za-z0-9]+)&t=([A-Za-z0-9]+)&zum=korb
RewriteRule ^carrito/recordatorio(?:/|/index\.html|\.html)?$ /carrito/recordatorio/%1/%2/carrito.html? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+carrito/recordatorio(?:/|/index\.html|\.html)?\?e=([A-Za-z0-9]+)&t=([A-Za-z0-9]+)
RewriteRule ^carrito/recordatorio(?:/|/index\.html|\.html)?$ /carrito/recordatorio/%1/%2.html? [R=301,L]

# ---- 2. alte Ordner-Adressen (mit oder ohne « / », auch « …/index.html ») → .html (301 ; übrige Angaben bleiben)
RewriteRule ^(devoluciones-y-reembolsos|derecho-de-desistimiento|politica-de-privacidad|condiciones-generales|desistir-del-contrato|carrito/recordatorio|preguntas-frecuentes|politica-de-cookies|seguimiento-pedido|envios-y-entregas|finalizar-compra|pedido-recibido|formas-de-pago|quienes-somos|aviso-legal|favoritos|contacto|garantia|carrito|buscar|tienda)(?:/|/index\.html)?$ /$1.html [R=301,L]
RewriteRule ^(producto|categoria)/([a-z0-9-]+)(?:/|/index\.html)?$ /$1/$2.html [R=301,L]

# ---- 3. neue Adressen mit Angaben im Dateinamen → Seite des Builds (interne Umschreibung, die Adresse bleibt stehen)
RewriteRule ^buscar/[^/]+\.html$ buscar.html [L]
RewriteRule ^pedido-recibido/[A-Za-z0-9-]+/[A-Za-z0-9]+(?:/tarjeta|/bizum|/bizum-cancelado)?\.html$ pedido-recibido.html [L]
RewriteRule ^seguimiento-pedido/[A-Za-z0-9-]+/[A-Za-z0-9]+\.html$ seguimiento-pedido.html [L]
RewriteRule ^carrito/recordatorio/[A-Za-z0-9]+/[A-Za-z0-9]+(?:/baja|/carrito)?\.html$ carrito/recordatorio.html [L]

# ---- 4. Produkt- oder Kategorieseite ohne Datei : nicht veröffentlichter oder entfernter Artikel → 301, sonst 404 (api/redireccion.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(producto|categoria)/([a-z0-9-]+)\.html$ api/redireccion.php?art=$1&slug=$2 [L]
</IfModule>

<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
<FilesMatch "\.(html|php)$">
Header set Cache-Control "no-cache"
</FilesMatch>
<FilesMatch "\.(webp|jpg|woff2|svg)$">
Header set Cache-Control "public, max-age=2592000"
</FilesMatch>
<FilesMatch "\.(css|js)$">
Header set Cache-Control "public, max-age=604800"
</FilesMatch>
# vom Serverprogramm geschriebene Daten (Preise, Lieferarten, sichtbare Produkte) : nach css|js, damit diese Regel gilt
<FilesMatch "^(shop|katalog)\.js$">
Header set Cache-Control "no-cache"
</FilesMatch>
</IfModule>
