Skip to content

Support for rewrites #5703

Closed
Closed
@kyjus25

Description

@kyjus25

Describe the problem

Probably kind of a huge undertaking, but it would be great to have rewrite support in SvelteKit similar to what Next.js can do.

The big hurdle for me comes when trying to convert existing PHP sites to SvelteKit. In PHP we'd have .htaccess to handle rewrites, but JS would require either the framework handling it, or a reverse proxy handling it beforehand (which is not helpful during development).

Static uploads are also something I'd love to be able to perform rewrites for. There's one site in particular I cannot convert because it acts as a monorepo for several other websites that share one common uploads directory separated by domain names.

For instance, when /example.png is accessed, PHP is rewriting it to /uploads/<domain>/images/example.png, which I believe is not possible to do in SvelteKit currently. Vite can change the assets path, but it is not dynamic. hooks.js can redirect, but ideally I would like to abstract the path away from the user so they never see the true source.

Describe the proposed solution

Implement something similar to Next.js' rewrite solution, or the ability to rewrite from handle or load functions as opposed to redirect.

Alternatives considered

Apart from having a reverse proxy in front, I don't believe there is a true solution currently.

The handle function can perform a redirect, but not a rewrite.

Under certain circumstances you could kludge up a [...catchall].svelte to redirect the requests, but also is not rewriting.

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions