redirection
redirection copied to clipboard
Prevent duplicate rules
It would be great to be able to find duplicate rules and/or flagging them when they are added.
To me a duplicate rule is anything with the same source URL, but a possibly duplicate rule is anything with a string of X characters in common, with X best implemented as a configurable setting.
+1 to this- we've had a couple flaky redirections due to this issue.
No? Nothing? @johngodley ?
@galbaras This plugin doesn't seem to get much love- which is sad :frowning:
OK, so I've just given it some love (good review, that is). With 500,000+ installs, I think it's worth the investment.
Come to think of it, features like a better bulk upload interface and automatic renaming of all posts types, all uploads, all taxonomies and all terms would make this plugin truly remarkable and worth all the love in the world :)
I don't think it's necessary while adding a redirect manually (I use always the search feature). Actually after 10 years I noticed it recently that I'm able to create the same rule twice :) It becomes worse if you use the Import feature while handling hundreds of rules. Will say yes, a check for duplicates might be very useful (for identical source and target pairs)
+1
So this rule checker could run as it's own batch job. I don't think it needs to correct the issues in the first version, just highlight then.
- Build up buffer of all source URLs, dest URLs & rule IDs
- iterate through all rules and find those with the same source url & <> current rule id
- iterate through all rules and find those where source == destination
First version could just do literal match. Next could do regex test. Multiple chains, after that.
I'm trying to implement this for a client that needs it ASAP. Is this a reliable way of checking if an URL has a matching redirect? It's basically a copy of https://github.com/johngodley/redirection/blob/0ae863160ff0807ca26f75bc49bb3ebef16d186d/modules/wordpress.php#L312.
public function getMatchingItem(string $url): ?Red_Item
{
$request = new Red_Url_Request($url);
// Make sure we don't try and redirect something essential
if (! $request->is_valid() || $request->is_protected_url()) {
return null;
}
// Get all redirects that match the URL
$redirects = Red_Item::get_for_url($request->get_decoded_url());
// Redirects will be ordered by position. Run through the list until one fires
foreach ($redirects as $item) {
$action = $item->get_match($request->get_decoded_url(), $request->get_original_url());
if ($action) {
return $item;
}
}
return null;
}
Just want to give this a +1 as well.
Detection of redirect loops would be super helpful when importing a large number of redirects. It would also be helpful for clients who may not have enough knowledge regarding redirection loops.
I think the steps laid out by @XVII are a great place to start.