Skip to content
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

Prevent duplicate rules #82

Open
galbaras opened this issue Nov 21, 2015 · 9 comments
Open

Prevent duplicate rules #82

galbaras opened this issue Nov 21, 2015 · 9 comments

Comments

@galbaras
Copy link

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.

@madysondesigns
Copy link

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

@galbaras
Copy link
Author

No? Nothing? @johngodley ?

@madysondesigns
Copy link

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

@galbaras
Copy link
Author

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

@finalwebsites
Copy link

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)

@leopoiroux
Copy link

+1

@XVII
Copy link

XVII commented May 3, 2021

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.

@stefanfisk
Copy link
Contributor

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

public function init() {
.

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

@RubenAhlhaus
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants