Resolve URLs through composed redirects and canonicals
Source:R/resolve_canonicals.R
resolve_folded_urls.RdResolves URL vectors with the same composed 3xx redirect plus declared `rel=canonical` fold-map engine used by [pagerank()] and [build_fold_map()]. This helper performs signal folding only; it does not perform URL syntax canonicalization.
Usage
resolve_folded_urls(
urls,
redirects_df = NULL,
canonicals_df = NULL,
redirect_from_col = "from",
redirect_to_col = "to",
canonical_from_col = "from",
canonical_to_col = "to",
duplicate_from_policy = c("strict", "first_wins", "last_wins", "most_frequent",
"prune_source", "resolve_if_consistent"),
loop_handling = c("error", "prune_loop", "break_arrow"),
canonical_duplicate_from_policy = c("strict", "first_wins", "last_wins",
"most_frequent", "prune_source", "resolve_if_consistent"),
canonical_loop_handling = c("error", "prune_loop", "break_arrow"),
canonical_conflict_policy = c("redirect_wins", "error", "canonical_wins")
)Arguments
- urls
Character vector of URLs to resolve.
- redirects_df
Optional data frame of redirect rules, or `NULL`.
- canonicals_df
Optional data frame of declared canonical links, or `NULL`.
- redirect_from_col, redirect_to_col
From/to columns in `redirects_df`. Default `"from"` / `"to"`.
- canonical_from_col, canonical_to_col
From/to columns in `canonicals_df`. Default `"from"` / `"to"`.
- duplicate_from_policy
How to handle a redirect source with multiple distinct targets. See [resolve_redirects()]. Default `"strict"`.
- loop_handling
How to handle redirect cycles. See [resolve_redirects()]. Default `"error"`. Also governs cross-signal cycles in the composed graph.
- canonical_duplicate_from_policy
How to handle a canonical source with multiple distinct declared canonicals. Reuses the `duplicate_from_policy` enum. Default `"strict"`.
- canonical_loop_handling
How to handle cycles among declared canonicals. Reuses the `loop_handling` enum. Default `"error"`.
- canonical_conflict_policy
How to resolve a redirect-vs-canonical disagreement on the **same source** URL. One of:
- `"redirect_wins"`
(Default) The 3xx redirect wins; a canonical declared on a URL that itself redirects is ignored and flagged, never transferred onto the redirect target.
- `"error"`
Error when a redirect and a canonical disagree on the same source (after audit context is computed). Sources where the two signals agree do not error.
- `"canonical_wins"`
The declared canonical wins for that source; still flagged in the audit. The explicit exception to the default ignored-canonical-on-redirecting-source rule.
Value
A data frame with `original`, `resolved`, `changed`, and `signal` columns. The exported fold map is attached as attribute `"fold_map"` and cross-signal audit tables are attached as `"conflicts"` and `"ignored_canonicals"`.
Examples
redirects <- data.frame(from = "B", to = "C")
canonicals <- data.frame(from = "A", to = "B")
resolve_folded_urls(c("A", "B", "X"), redirects, canonicals)
#> original resolved changed signal
#> 1 A C TRUE canonical
#> 2 B C TRUE redirect
#> 3 X X FALSE <NA>