Skip to content

Trailing slash normalization always redirects against root #13718

Open
@HoldYourWaffle

Description

@HoldYourWaffle
Contributor

Describe the bug

Related: #595 and #13702.

I need to integrate a SvelteKit app into an existing Express.js server at a dynamic base path. Based on #595 (comment) I assume this is intended to be supported through the kit.paths.relative option, but trailing slash normalization seems to assume SvelteKit is top dog and redirects against the root.

Standard static paths.base behavior (repro branch)

With a configuration like this:

const config = {
	kit: {
		adapter: adapterNode(),
		paths: {
			base: '/sveltekit',
			relative: true
		}
	}
}

...and integration into a custom server like this:

app.use(handler);

/sveltekit/sverdle/ is correctly redirected to /sveltekit/sverdle.

Dynamic paths.base attempt (repro branch)

With a configuration like this:

const config = {
	kit: {
		adapter: adapterNode(),
		paths: {
			relative: true
		}
	}
};

...and integration like this:

app.use('/sveltekit', handler);

/sveltekit/sverdle/ is incorrectly redirected to /sverdle.

Reproduction

HoldYourWaffle/sveltekit-express-dynamic-basepath, specifically repro--static-base and repro--dynamic-base.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 16.98 GB / 31.81 GB
  Binaries:
    Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.6.2 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (133.0.3065.69)
    Internet Explorer: 11.0.19041.4355

Severity

blocking all usage of SvelteKit

Additional Information

The Location header is allowed to be relative (MDN), so I think this should be an easy fix?™
Already working on a PR :)

Activity

changed the title [-]`trailingSlash` redirects against root instead of dynamic base[/-] [+]`trailingSlash` always redirects against root[/+] on Apr 16, 2025
changed the title [-]`trailingSlash` always redirects against root[/-] [+]Trailing slash normalization always redirects against root[/+] on Apr 16, 2025
eltigerchino

eltigerchino commented on Apr 18, 2025

@eltigerchino
Member

I think the issue is that Express strips the mount path from the request URL, so if you have app.use('/sveltekit', handler) and a user navigates to /sveltekit/about , SvelteKit receives a different URL /about. While some routing features work, it breaks features such as redirects, links, URL information, etc. #7242 (comment) sums this up well

HoldYourWaffle

HoldYourWaffle commented on Apr 20, 2025

@HoldYourWaffle
ContributorAuthor

Just to double check - are you sure you didn't mix this up with #13702? I agree that both are strongly related to #7242, but this specific problem has a much simpler solution (#13719).

eltigerchino

eltigerchino commented on Apr 21, 2025

@eltigerchino
Member

Sorry, after thinking about it more, the fix you've proposed should work even if the URL passed to SvelteKit is missing the base path. For example, if the requested path is /base-path/about and SvelteKit receives /about, it will result in the same relative redirect such as ../about/. While this doesn't fix all the base path issues that a fix for #7242 would, I think it could be useful to have these relative redirects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @HoldYourWaffle@eltigerchino

      Issue actions

        Trailing slash normalization always redirects against root · Issue #13718 · sveltejs/kit