From fdd19ce874c7e5f3e5200a95c70180b88cbfcb01 Mon Sep 17 00:00:00 2001 From: Anthony GAEREMYNCK <1@anthony.sh> Date: Sun, 2 Aug 2026 16:02:17 +0200 Subject: [PATCH] feat: add root language redirect for o2switch hosting --- public/.htaccess | 6 ++++++ tests/htaccess.test.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 public/.htaccess create mode 100644 tests/htaccess.test.ts diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..f1ba3e0 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,6 @@ +RewriteEngine On +RewriteCond %{REQUEST_URI} ^/$ +RewriteCond %{HTTP:Accept-Language} fr [NC] +RewriteRule ^$ /fr/ [R=302,L] +RewriteCond %{REQUEST_URI} ^/$ +RewriteRule ^$ /en/ [R=302,L] diff --git a/tests/htaccess.test.ts b/tests/htaccess.test.ts new file mode 100644 index 0000000..7642e56 --- /dev/null +++ b/tests/htaccess.test.ts @@ -0,0 +1,17 @@ +import { describe, it, expect, beforeAll } from 'vitest'; +import { execSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; + +describe('root language redirect', () => { + beforeAll(() => { + execSync('npm run build', { stdio: 'inherit' }); + }); + + it('copies .htaccess to dist with the french/english redirect rules', () => { + const htaccess = readFileSync('dist/.htaccess', 'utf-8'); + expect(htaccess).toContain('RewriteEngine On'); + expect(htaccess).toContain('HTTP:Accept-Language} fr'); + expect(htaccess).toContain('RewriteRule ^$ /fr/ [R=302,L]'); + expect(htaccess).toContain('RewriteRule ^$ /en/ [R=302,L]'); + }); +});