Redirects & Rewrites
Redirects & Rewrites
Section titled “Redirects & Rewrites”Wisp.place supports Netlify-style _redirects files, giving you powerful control over URL routing and redirects. Whether you’re migrating an old site, setting up a single-page app, or creating clean URLs, the _redirects file lets you handle complex routing scenarios without changing your actual file structure.
Getting Started
Section titled “Getting Started”Drop a file named _redirects in your site’s root directory. Each line defines a redirect rule with the format:
/from/path /to/path [status] [conditions]For example:
/old-page /new-page/blog/* /posts/:splat 301Basic Redirects
Section titled “Basic Redirects”The simplest redirects move traffic from one URL to another:
/home //about-us /about/old-blog /blogThese use a permanent redirect (301) by default, telling browsers and search engines the page has moved permanently.
Status Codes
Section titled “Status Codes”You can specify different HTTP status codes to change how the redirect behaves:
301 - Permanent Redirect
/legacy-page /new-page 301Tells browsers and search engines the page has moved permanently. Good for SEO when content has truly moved.
302 - Temporary Redirect
/temp-sale /sale-page 302Indicates a temporary move. Browsers won’t cache this as strongly, and search engines won’t transfer SEO value.
200 - Rewrite
/api/* /functions/:splat 200Serves different content but keeps the original URL visible to users. Perfect for API routing or single-page apps.
404 - Custom Error Page
/shop/* /shop-closed.html 404Shows a custom error page instead of the default 404. Useful for seasonal closures or section-specific error handling.
Force with !
/existing-file /other-file 200!Normally, if the original path exists as a file, the redirect won’t trigger. Add ! to force it anyway.
Wildcard Redirects
Section titled “Wildcard Redirects”Splats (*) let you match entire path segments:
Simple wildcards:
/news/* /blog/:splat/old-site/* /new-site/:splatIf someone visits /news/tech-update, they’ll be redirected to /blog/tech-update.
Multiple wildcards:
/products/*/details/* /shop/:splat/info/:splatThis captures multiple path segments and maps them to the new structure.
Placeholders
Section titled “Placeholders”Placeholders let you restructure URLs with named parameters:
/blog/:year/:month/:day/:slug /posts/:year-:month-:day/:slug/products/:category/:id /shop/:category/item/:idThese are more precise than splats because you can reference the captured values by name. Visiting /blog/2024/01/15/my-post redirects to /posts/2024-01-15/my-post.
Query Parameters
Section titled “Query Parameters”You can match and redirect based on URL parameters:
/store?id=:id /products/:id/search?q=:query /find/:queryThe query parameter becomes part of the redirect path. /store?id=123 becomes /products/123.
Conditional Redirects
Section titled “Conditional Redirects”Make redirects happen only under certain conditions:
Country-based:
/ /us/ 302 Country=us/ /uk/ 302 Country=gbRedirects users based on their country (using ISO 3166-1 alpha-2 codes).
Language-based:
/products /en/products 301 Language=en/products /de/products 301 Language=deRoutes based on browser language preferences.
Cookie-based:
/* /legacy/:splat 200 Cookie=is_legacyOnly redirects if the user has a specific cookie set.
Advanced Patterns
Section titled “Advanced Patterns”Single-page app routing:
/* /index.html 200Send all unmatched routes to your main app file. Perfect for React, Vue, or Angular apps.
API proxying:
/api/* https://api.example.com/:splat 200Proxy API calls to external services while keeping the URL clean.
Domain redirects:
http://blog.example.com/* https://example.com/blog/:splat 301!Redirect from subdomains or entirely different domains.
Extension removal:
/page.html /pageClean up old .html extensions for a modern look.
How It Works
Section titled “How It Works”- Processing order: Rules are checked from top to bottom - first match wins
- Specificity: More specific rules should come before general ones
- Caching: Redirects are cached for performance but respect the site’s cache headers
- Performance: All processing happens at the edge, close to your users
Examples
Section titled “Examples”Here’s a complete _redirects file for a typical site migration:
# Old blog structure to new/blog/* /posts/:splat 301
# API proxy/api/* https://api.example.com/:splat 200
# Country redirects for homepage/ /us/ 302 Country=us/ /uk/ 302 Country=gb
# Single-page app fallback/* /index.html 200
# Custom 404 for shop section/shop/* /shop/closed.html 404- Order matters: Put specific rules before general ones
- Test thoroughly: Use the preview feature to check your redirects
- Use 301 for SEO: Permanent redirects pass SEO value to new pages
- Use 200 for SPAs: Rewrites keep your app’s routing intact
- Force when needed: The
!flag overrides existing files - Keep it simple: Most sites only need a few redirect rules
Troubleshooting
Section titled “Troubleshooting”Redirect not working?
- Check the order - rules are processed top to bottom
- Make sure the file is named exactly
_redirects(no extension) - Verify the file is in your site’s root directory
Wildcard not matching?
- Wildcards only work at the end of paths
- Use placeholders for more complex restructuring
Conditional redirect not triggering?
- Country detection uses IP geolocation
- Language uses Accept-Language headers
- Cookies must match exactly
The _redirects system gives you the flexibility to handle complex routing scenarios while keeping your site structure clean and maintainable.