Project

General

Profile

Bug #2449 » .htaccess

Bernhard Koschiček-Krombholz, 2025-10-28 14:35

 
# Enable rewriting
RewriteEngine On

# =========================
# 0) CONFIG: supported locales
# =========================
# Update the list (en|de|fr|...) everywhere below if you add more locales.
# Already localized? do nothing
RewriteCond %{REQUEST_URI} ^/(en|de)(/|$) [NC]
RewriteRule ^ - [L]

# =========================
# 1) Bypass static files & API endpoints
# =========================
RewriteCond %{REQUEST_URI} ^/(assets|dist|_nuxt|static|img|images|css|js|fonts|favicon\.ico|robots\.txt|sitemap\.xml|api)(/|$) [NC]
RewriteRule ^ - [L]

# =========================
# 2) Localize specific routes: /entity/<id>
# =========================
# 2a) Prefer Nuxt/Vue i18n cookie (i18n_redirected)
RewriteCond %{REQUEST_URI} ^/entity/([0-9]+)$
RewriteCond %{HTTP:Cookie} (^|;\s*)i18n_redirected=(en|de) [NC]
RewriteRule ^entity/([0-9]+)$ %2/entity/%1 [R=302,L,QSA]

# 2b) Or a generic language cookie (lang=en|de)
RewriteCond %{REQUEST_URI} ^/entity/([0-9]+)$
RewriteCond %{HTTP:Cookie} (^|;\s*)lang=(en|de) [NC]
RewriteRule ^entity/([0-9]+)$ %2/entity/%1 [R=302,L,QSA]

# 2c) Otherwise infer from Accept-Language (German if it starts with "de")
RewriteCond %{REQUEST_URI} ^/entity/([0-9]+)$
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^entity/([0-9]+)$ de/entity/%1 [R=302,L,QSA]

# 2d) Fallback to English
RewriteCond %{REQUEST_URI} ^/entity/([0-9]+)$
RewriteRule ^entity/([0-9]+)$ en/entity/%1 [R=302,L,QSA]

# =========================
# 3) SPA fallback for Vue/Nuxt history mode
# =========================
# (keeps localized paths working too)
RewriteRule ^ - [E=REWRITEBASE:/]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
(1-1/2)