dub icon indicating copy to clipboard operation
dub copied to clipboard

[FEAT]: Redirect rule

Open steven-tey opened this issue 1 year ago • 7 comments

Ability to define a redirect rule for a given route pattern instead of manually defining all the links.

E.g. doma.in/:path → domain.com/products/:path

Use case: ShareGPT → https://shareg.pt/bPdEf2F redirects to https://sharegpt.com/c/bPdEf2F

steven-tey avatar Jan 02 '24 03:01 steven-tey

Hi steven! Can we leverage the redirects configuration in next.config.js?

module.exports = { async redirects() { return [ { source: '/doma.in/:path*', // Match any path starting with '/doma.in/' destination: 'https://domain.com/products/:path*', // Preserve the original path permanent: false, // Optional: Set to true for a permanent (308) redirect }, ]; }, };

hemant-code625 avatar Jan 02 '24 04:01 hemant-code625

Hi @hemant-code625! That won't be possible in our case since we're using edge middleware to handle redirects. We'll also have to rethink our existing redirect logic (GETa kv-pair from Redis and redirect if exists) and adapt that to this use case.

steven-tey avatar Jan 03 '24 02:01 steven-tey

Thank you @steven-tey for clarifying. Let me learn about this edge middleware and our codebase, I'll be back to resolve this issue soon.

hemant-code625 avatar Jan 03 '24 03:01 hemant-code625

Some ideas:

  • MySQL: Redirect rules are basically still links, but with an extra column (rule: true)
  • Redis: Make the usual Redis call to get a link, if not found, make a second call to find redirect rule
  • Tinybird: Log clicks under main redirect rule link and add the clicked path as the alias_link_Id?

steven-tey avatar Feb 22 '24 15:02 steven-tey

@steven-tey as we talked about via email, I'm sharing my input here.

We would love wildcards in links - for instance domain/introduction-deck/* - for which we could input anything, e.g. introduction-deck/clientA, introduction-deck/clientB. It would always redirect to the parent link /introduction-deck but track each child link (the wildcard). This makes it much faster for our sales team to share material without needing to create new links.

For analytics, initially a simple table view would be fine. A more advanced solution would be two analytics pages: 1) parent links and 2) child links which required a selection of a parent through a dropdown or similar. The advanced solution might not be feasible with the overall product direction, so a REST API to extract data would also be just fine (i.e. GET call with date params to get all links with analytics per day - we can parse the rest).

lessthomas avatar May 06 '24 07:05 lessthomas

Appreciate the input here @lessthomas 🙏

steven-tey avatar May 10 '24 14:05 steven-tey