Support for wildcards

Created on 30 November 2016, about 8 years ago
Updated 19 March 2023, almost 2 years ago

I would like to make a request for support for wildcard redirects.

For instance if I have a lot of requests for a legacy Drupal 6 path like /members/calendar/2014-03 and I would like to redirect them to the Drupal 8 calendar which has an entirely different path like /events/calendar-of-events/2014-03

Ideally, I could use tokens so that the actual date part is useful but at this point, I'd settle for just redirecting them to a static path like: /events/calendar-of-events/month

The From field would be: /members/calendar/*
The to field would be: /events/calendar-of-events/month

Thanks.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada awasson

Live updates comments and jobs are added and updated live.
  • needs profiling

    It may affect performance, and thus requires in-depth technical reviews and profiling.

  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡·πŸ‡ΊRussia vvs Russia

    @ricardofaria thanks for #114 it's working for my conditions:
    /recipe/* -> /recipes/*

    With one file rejected:

    --- src/RedirectRepository.php
    +++ src/RedirectRepository.php
    @@ -188,7 +243,6 @@ class RedirectRepository {
        */
       public function findBySourcePath($source_path) {
         $ids = $this->manager->getStorage('redirect')->getQuery()
    -      ->accessCheck(TRUE)
           ->condition('redirect_source.path', $source_path, 'LIKE')
           ->execute();
         return $this->manager->getStorage('redirect')->loadMultiple($ids);
    @@ -206,7 +260,6 @@ class RedirectRepository {
       public function findByDestinationUri(array $destination_uri) {
         $storage = $this->manager->getStorage('redirect');
         $ids = $storage->getQuery()
    -      ->accessCheck(TRUE)
           ->condition('redirect_redirect.uri', $destination_uri, 'IN')
           ->execute();
         return $storage->loadMultiple($ids);
    

    but worked in redirect 1.7.

    It's rejected because code is:

      public function findBySourcePath($source_path) {
        $ids = $this->manager->getStorage('redirect')->getQuery()
          ->accessCheck(TRUE)
          ->condition('redirect_source.path', $source_path, 'LIKE')
          ->execute();
        return $this->manager->getStorage('redirect')->loadMultiple($ids);
      }
    
    
  • πŸ‡¨πŸ‡¦Canada bgilhome Victoria

    @vidorado there's an undefined variable $query in your patch in #104 ✨ Support for wildcards Needs work - line 165 of RedirectRepository.php.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    #114 is working for me in Drupal 9.5.10.

    I could redirect /properties-location/* to /properties/* while leaving /properties-location untouched.

  • πŸ‡ΊπŸ‡ΈUnited States sidgrafix

    Patch broke on latest release of redirect so here is an updated patch (same as #114, applied to latest version of redirect).

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    run-tests.sh fatal error
  • πŸ‡ΊπŸ‡ΈUnited States msypes

    Tested patch from #120 with core 10.1.5 and redirect 1.9.
    With a "From" /foo/bar/* no redirect occurred from either /foo/bar/baz nor /foo/bar/baz/bing. Was hoping for something similar to #119, using a "To" of /foo/bar. Looks like that creates a redirect loop, according to the logs, which isn't surprising, but incompatible with my use case.
    I also note however, that editing the "To" to /foo didn't result in any redirects either, which is surprising.
    I can't say that this patch works at all.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Sure, patch #114 broke on the latest release and #120 applied successfully.

  • πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

    @sidgrafix: it doesn't appear your patch is a simple reroll ("the same as #114, applied to latest version"). There are a number of material differences. Are the other changes intentional (to get this working) or an accident?

    Here is #114 rerolled for the current 8.x-1.x, with the one rejected hunk fixed, (plus a diff of these two patches for verification).

    Leaving this as Needs Work, as @azinck's recommendations in #106 are still not addressed.

  • πŸ‡ΊπŸ‡ΈUnited States sidgrafix

    @jeffschuler - All I did was reroll patch from comment 114 listed as support-for-wildcard-2831605-113.patch (if you compare that to mine they are identicle.

    Per "ricardofaria" post 114 he said "Created a patch with a little difference from the previous one. Will need to review this later, but for now its working for me."

    - Any changes you mention (if they diverged from the patch prior to support-for-wildcard-2831605-113.patch) were done there in support-for-wildcard-2831605-113.patch before I rerolled.. I assumed that patch was the previous current working if it is not "my bad", apologies for any confusion. Tho the patch has been working fine for me!

  • πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

    @sidgrafix your patch in #120 and the patch in #114 are not identical.

    For example, the patch in #114 has this change:

    -    $this->assertSession()->statusCodeEquals(404);
    +    $this->assertResponse(404, 'Deleted redirect properly clears the internal page cache.');
    

    while your patch does not.

    The #114 patch removes this line:

    -    $this->assertSession()->pageTextContains('No URL redirects available.');
    

    but yours doesn't:

         $this->assertSession()->pageTextContains('No URL redirects available.');
    

    The #114 patch calls drupalPostForm:

    +    $this->drupalPostForm('node/' . $node->id() . '/edit', ['path[0][alias]' => '/node_test_alias_updated'], t('Save'));
    

    and yours calls drupalPostFormForm:

    +    $this->drupalPostFormForm('node/' . $node->id() . '/edit', ['path[0][alias]' => '/node_test_alias_updated'], t('Save'));
    

    ...

  • πŸ‡ΊπŸ‡ΈUnited States sidgrafix

    @jeffschuler - I honestly not entirely sure being 5 months ago, there is a chance I patched a non-dev version then by accident and the slight differences in the lines you mention would have been changed in accordance with whatever version of redirect I was patching.

    Looking at the composer.json for the site I used patch 120 on I patched redirect 8.x-1.9 (which was for a D9.5 sight, since updated to 10.2.2) again apologies for any confusion this may have caused..

  • πŸ‡ΊπŸ‡ΈUnited States jeffschuler Boulder, Colorado

    No prob; just want to see this issue continue forward!

  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)

    I can confirm what Azinck says in #106

    Another test that really should be added is to test the interaction with paths that have similarities to the redirected path. For instance, patch 101 introduced a significant bug with this code: $rule->pattern = mb_strtolower(str_replace('/*', '*', $rule->pattern)); -- that causes redirect loops if you create a redirect like:
    /foo/* => /foobar/*
    That's due to the fact that /foo/* pattern is now really being interpreted as /foo*...which is just not correct. But the tests didn't catch that error.

    A redirect /r/* has become /r* which is a CRITICAL bug

    The patch from #123 has the problematic line commented:
    // $rule->pattern = mb_strtolower(str_replace('/*', '*', $rule->pattern));

    And now that bug has gone.

    Anybody remembers what was the purpose of that str_replace()? It does not make sense for me right now...

  • πŸ‡ΊπŸ‡ΈUnited States ceithamer728

    Patch #123 was broken for us in Drupal 10.2.5 as it was removing the now required accessCheck(TRUE) calls from RedirectRepository class.

    My patch just adds those two lines of code back.

  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)

    The patch in #129 commented the line

    // $rule->pattern = mb_strtolower(str_replace('/*', '*', $rule->pattern));

    And two thing where stripped out:

    - The replacing of '/*' to '*'.
    - But ALSO making the rule case insensitive.

    I attach a new patch to restore the latter.

  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 178s
    #178015
  • πŸ‡§πŸ‡ͺBelgium matthijs

    We noticed a performance impact on our project due to this patch (the query took often 300-500ms) and decided to remove it.
    As a safety (in case it ever gets merged) I converted the patch from #130 into an MR and added a config option to enable wildcard support.

    I did not update any tests, these might still need changes.

  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 165s
    #186421
  • πŸ‡§πŸ‡ͺBelgium jelle_s Antwerp, Belgium

    I've not been able to test yet, but I was wondering what this patch/MR would do if there are these wildcard redirects:

    a-path/* -> redirect1.com
    a-path/b-path/* -> redirect2.com
    

    and you would navigate to a-path/b-path/c-path, which redirect would it use?

  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)

    @Jelle_S It will select the second one, as it is the more specific one (determined by being the longer string)

  • Pipeline finished with Success
    6 months ago
    Total: 228s
    #215608
  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)
  • πŸ‡ΊπŸ‡¦Ukraine chizh273

    I can't update the MR on the GitLab so here's a new version with resolved merge conflict.

  • Pipeline finished with Success
    about 2 months ago
    Total: 212s
    #319138
  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)
  • πŸ‡«πŸ‡·France GaΓ«lG Lille, France

    @chizh273 If you click on the green button "Get push access" above, you should be able to update the MR. Anyway, @vidorado dit it.

  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)

    Thanks for the review @gaelg! It is very useful to polish the feature.

    I will get into it tomorrow 😊

  • Pipeline finished with Success
    11 days ago
    Total: 231s
    #364762
  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)

    I've made some changes to address the issues identified by @gaelg, but I can't resolve the threads on git.drupalcode.org; I don't see any button to do so...

  • πŸ‡«πŸ‡·France prudloff Lille

    I think only the creator of the MR, the person who started the thread or the maintainers of the module can mark threads as resolved.

  • πŸ‡«πŸ‡·France GaΓ«lG Lille, France

    Thank you for the work @vidorado! I cannot resolve threads either. @Matthijs?

  • πŸ‡§πŸ‡ͺBelgium matthijs

    @vidorado @gaΓ«lg I resolved them all.

  • πŸ‡·πŸ‡ΊRussia zniki.ru

    Thanks for update MR, please check my feedback.

  • Pipeline finished with Success
    10 days ago
    Total: 185s
    #366708
  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)
  • Pipeline finished with Success
    10 days ago
    Total: 180s
    #366883
  • πŸ‡ͺπŸ‡ΈSpain vidorado Pamplona (Navarra)

    Tests added! :)

    Thanks for the review @nikolay

  • πŸ‡·πŸ‡ΊRussia zniki.ru

    Thanks for removing all unrelated changes, and MR update.
    It's much easier to review now.
    I left my feedback.
    But it would be great someone else also check MR.

Production build 0.71.5 2024