Skip to content

Redirections

Quark supports HTTP redirections to automatically redirect clients from one URL to another. This is useful for migrating domains, enforcing URL patterns, or redirecting old URLs to new locations.

When a user visits https://example.com/old-page/, they will be redirected to https://example.com/new-page/. By default, redirections use a 301 (Permanent) status code.

[[services.my_site.redirections]]
source = "/old-path/"
target = "https://example.com/new-path/"

This configuration:

  • Matches: /old-path/ exactly
  • Does not match: /old-path/page, /old-path/anything
  • The target URL replaces the source completely

Wildcard redirections preserve the path suffix from the original URL:

[[services.my_site.redirections]]
source = "/blog/*"
target = "https://newsite.com/articles/"

This configuration:

  • /blog/https://newsite.com/articles/
  • /blog/post-1https://newsite.com/articles/post-1
  • /blog/category/techhttps://newsite.com/articles/category/tech

The asterisk (*) at the end of the source path indicates that the remaining part of the URL should be preserved and appended to the target.

You can specify different HTTP status codes for redirections:

[[services.my_site.redirections]]
source = "/temporary/*"
target = "https://example.com/new/"
code = 302

Supported status codes:

CodeDescriptionUse Case
301Permanent redirection (default, cached by browsers)Use for permanent URL changes (SEO-friendly, browsers cache it)
302Temporary redirection (not cached)Use for temporary redirections (maintenance, A/B testing)
307Temporary redirection (preserves HTTP method)Like 302, but guarantees POST requests stay POST
308Permanent redirection (preserves HTTP method)Like 301, but guarantees POST requests stay POST

Quark automatically handles www subdomain redirections based on how you define your domain in the service configuration.

If you want www.example.com to redirect to example.com, simply define your domain without the www prefix:

[services.my_site]
domain = "example.com"

If you want example.com to redirect to www.example.com, define your domain with the www prefix:

[services.my_site]
domain = "www.example.com"

The redirection is automatic and permanent (301), preserving the full path and query string.