From 69290f3192b5583bb77179fa3c8cdc12a5e9a657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Veikko=20Lintuj=C3=A4rvi?= Date: Thu, 4 Dec 2025 20:15:56 +0200 Subject: [PATCH] Fix .htaccess handling in Vite build --- package.json | 2 +- public/.htaccess | 19 ++++++++++++++++--- vite.config.ts | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 895c79f..04695a4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "scripts": { "dev": "vite", - "build": "run-p type-check \"build-only {@}\" --", + "build": "run-p type-check \"build-only {@}\" -- && cp public/.htaccess dist/.htaccess", "preview": "vite preview", "build-only": "vite build", "type-check": "vue-tsc --build", diff --git a/public/.htaccess b/public/.htaccess index 4dd8c31..172f2d3 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,8 +1,21 @@ + + Options -MultiViews + + RewriteEngine On - RewriteBase / - RewriteRule ^index\.html$ - [L] + + # Handle Authorization Header + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + # Redirect Trailing Slashes If Not A Folder... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_URI} (.+)/$ + RewriteRule ^ %1 [L,R=301] + + # Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule . /index.html [L] + RewriteRule ^ index.html [L] diff --git a/vite.config.ts b/vite.config.ts index d49d708..6e6712b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -17,4 +17,8 @@ export default defineConfig({ '@': fileURLToPath(new URL('./src', import.meta.url)) }, }, + publicDir: 'public', + build: { + copyPublicDir: true, + }, })