-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic rule-based redirects #1914
Comments
Preliminary persistence modelerDiagram
short_urls 1--many(0) short_url_redirect_rules : has
short_url_redirect_rules many(1)--many(1) redirect_conditions : has
short_urls {
string long_url
}
short_url_redirect_rules {
int short_url_id
int priority
string long_url
}
redirect_conditions {
string name UK "Example: device-android, query-foo-bar, language-en-US"
string type "enum(device, language, query...)"
string match_key "optional/nullable"
string match_value
}
EDIT: While implementing the API model, it was proved that a properly normalized persistence would get in the way, so conditions will finally not have a unique name nor be shared between rules. Every rule will have its set of conditions. This means more duplicated data in the database, but it should have a very low impact anyway. |
Dynamic redirectsShort URL redirects currently work like this:
With the new system, we can keep steps 1 and 3 unmodified, and the We'll have to inject a new service though, which will be the one iterating over rules and trying to match one. Every condition will try to be matched by using a type-specific plugin which knows how to extract and match the appropriate information from the Request object. |
API modelI'm thinking the simplest solution is to allow editing or listing rules and conditions always linked to a short URL, so the preliminary endpoints could look like this:
Then in the UI, we'll call the first one just before editing a short URL, and the second one after creating/editing a short URL succeeded. The only drawback about this approach is if the short URL creation works and saving the rules fails, which would leave an inconsistent state, but it's a negligible risk. The benefit is that it simplifies the short URL creation/edition endpoint, which was something that got more complex when device long URLs were implemented and I always regretted. |
CLI handlingI have realized device long URLs were never supported in the CLI, which I guess it's good now, as it's one less thing to change. For redirect rules, I think a set of new commands is the best approach. Something like EDIT: The complexity on the structure of rules and conditions, makes it hard to allow them to be programatically editable via command flags and arguments. So I will instead add a single command for now, EDIT 2: This is how it looks like. It's not perfect, but it should be usable. manage-rules-command.webm |
Summary
This RFC describes how dynamic redirects could be improved to support multiple combinations of rules, and then, be able to add more rules in future.
The first iteration should consist on preparing the base implementation for this to work, and potentially migrate device-specific long URLs to be the first supported redirect rule.
Use case
Supporting multiple dynamic redirect rules has been requested in the past, specially since device-specific redirects were implemented.
The text was updated successfully, but these errors were encountered: