#Redirect preserving URL tags
3 messages · Page 1 of 1 (latest)
Hi @orchid maple. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro’s routing docs don’t show a built‑in way to “redirect and preserve query params” in a single config entry, but you can achieve the behavior you want with a rewrite instead of a redirect.
A rewrite serves different content while keeping the original URL (including its query string) in the browser bar. So /work?tag=a&tag=b can show the same content as / without changing the URL. [Rewrites guide]
Create src/pages/work.astro:
---
const url = new URL(Astro.request.url);
// Build a URL pointing at "/", but keep the original search params
const target = new URL("/", url);
target.search = url.search;
return Astro.rewrite(target);
---
This:
- Keeps
/work?...in the address bar. - Renders the homepage (
/) content, with all original query parameters preserved and passed to that page. [rewrite() API]