Skip to content

fix: +redirects with a Base URL - #3615

Merged
nitedani merged 3 commits into
vikejs:mainfrom
nitedani:fix/redirects-base-full-url
Oct 15, 2026
Merged

nitedani merged 3 commits into
vikejs:mainfrom
nitedani:fix/redirects-base-full-url

Conversation

@nitedani

@nitedani nitedani commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 (high effort) wrote this and the code; another Opus 5.5 (high effort) reviewed it. WIP

With a Base URL, a +redirects entry answers 500 instead of 301 whenever the server passes Vike the full request URL, as Vike's built-in server, vike(app) and a +server.js do.

+redirects: { '/old-portal': '/portal' }, BASE=/app/ main This PR
GET /app/old-portal, +server: true, vike dev 500, [vike@0.4.267][Bug] … at prependBase … at getPermanentRedirect 301, location: http://localhost:3000/app/portal
The same after vike build, node dist/server/index.mjs 500, the same [Bug] 301, the same location

getPermanentRedirect() passed the whole target URL, origin included, to prependBase(), which expects a path. It now prepends the Base URL to the pathname only, with modifyUrlPathname(), which the function already uses a few lines above. A server that passes a path (vike dev and vike preview without +server) gets the same Location as before.

What you should see

1. A new run of test/plusMiddlewares' Base URL tests with +server: true in vike dev (.test-base-dev-server) fails on main and passes here:

# main (test commit only)
AssertionError: expected 500 to equal 301   (.testRun-base.ts:16)
# this PR
PASS

It's the only test of a Base URL where Vike gets the full request URL, as it does behind its built-in server, vike(app) and a +server.js.

As brillout asked, 0ab0638 removes that test before merge; the fix itself is unchanged.

2. Production, with the query string kept:

GET /app/old-portal      -> 301 location: http://localhost:3000/app/portal
GET /app/old-portal?a=1  -> 301 location: http://localhost:3000/app/portal?a=1
GET /app/portal          -> 200

🤖 Generated with Claude Code

nitedani and others added 2 commits October 15, 2026 01:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nitedani nitedani changed the title fix: +redirects with a Base URL behind a server that passes a full URL fix: [+redirects](https://vike.dev/redirects) with a Base URL answered 500 behind Vike's built-in server, vike(app) or a +server.js Oct 15, 2026
@nitedani
nitedani marked this pull request as ready for review October 15, 2026 00:18
@brillout brillout changed the title fix: [+redirects](https://vike.dev/redirects) with a Base URL answered 500 behind Vike's built-in server, vike(app) or a +server.js fix: +redirects with a Base URL Oct 15, 2026
@brillout

Copy link
Copy Markdown
Member

Remove the test then squash-merge (use the PR title as the entire commit message).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nitedani
nitedani merged commit 68a5edf into vikejs:main Oct 15, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants