redirection icon indicating copy to clipboard operation
redirection copied to clipboard

Prevent duplicate rules

Open galbaras opened this issue 10 years ago • 9 comments

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.

galbaras avatar Nov 21 '15 07:11 galbaras

+1 to this- we've had a couple flaky redirections due to this issue.

madysondesigns avatar Jan 11 '16 15:01 madysondesigns

No? Nothing? @johngodley ?

galbaras avatar Mar 13 '16 02:03 galbaras

@galbaras This plugin doesn't seem to get much love- which is sad :frowning:

madysondesigns avatar Mar 14 '16 15:03 madysondesigns

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 :)

galbaras avatar Mar 16 '16 00:03 galbaras

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)

finalwebsites avatar Jul 12 '19 07:07 finalwebsites

+1

leopoiroux avatar Oct 24 '19 07:10 leopoiroux

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.

XVII avatar May 03 '21 23:05 XVII

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;
}

stefanfisk avatar Oct 05 '22 10:10 stefanfisk

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.

RubenAhlhaus avatar Jul 31 '24 23:07 RubenAhlhaus