• This improvements address two things:
    * Some minor speed improvement
    * Avoid redirecting to where we just come from.

    I forked the file eps-301-redirects.php to eps-301-redirects-reh.php, and this is the patch:

    
    *** eps-301-redirects.php	2021-01-30 10:50:02.000000000 +0100
    --- eps-301-redirects-reh.php	2021-02-01 16:58:28.363247152 +0100
    ***************
    *** 119,128 ****
            $query_string = (isset($query_string[1])) ? $query_string[1] : false;
      
      
            foreach ($redirects as $redirect) {
              $from = urldecode(html_entity_decode($redirect->url_from));
      
    !         if ($redirect->status != 'inactive' && rtrim(trim($url_request), '/')  === self::format_from_url(trim($from))) {
      
                // Match, this needs to be redirected
                // increment this hit counter.
    --- 119,130 ----
            $query_string = (isset($query_string[1])) ? $query_string[1] : false;
      
      
    +       $url_request_canonical = rtrim(trim($url_request), '/');
    + 
            foreach ($redirects as $redirect) {
              $from = urldecode(html_entity_decode($redirect->url_from));
      
    !         if ($redirect->status != 'inactive' && $url_request_canonical  === self::format_from_url(trim($from))) {
      
                // Match, this needs to be redirected
                // increment this hit counter.
    ***************
    *** 138,146 ****
      
                $to = ($redirect->type == "url" && !is_numeric($redirect->url_to)) ? urldecode(html_entity_decode($redirect->url_to)) : get_permalink($redirect->url_to);
                $to = ($query_string) ? $to . "?" . $query_string : $to;
    ! 
    !           header('Location: ' . $to, true, (int)$redirect->status);
    !           exit();
              }
            }
          }
    --- 140,157 ----
      
                $to = ($redirect->type == "url" && !is_numeric($redirect->url_to)) ? urldecode(html_entity_decode($redirect->url_to)) : get_permalink($redirect->url_to);
                $to = ($query_string) ? $to . "?" . $query_string : $to;
    !           
    !           $do_redirect = true;
    !           $to_arr = parse_url($to);
    !           
    !           if (array_key_exists('path', $to_arr)) {
    !             $do_redirect = !( (rtrim($to_arr['path'], '/') === $url_request_canonical) );
    !           }
    !           
    !           if ($do_redirect) {
    !             header('Location: ' . $to, true, (int)$redirect->status);
    !             exit();
    !           }
              }
            }
          }
    
Viewing 1 replies (of 1 total)
  • Plugin Author WebFactory

    (@webfactory)

    Hi,
    Thank you very much for the patch! I’ll make sure the devs have a look and implement it ASAP if they feel it’s OK.

Viewing 1 replies (of 1 total)
  • The topic ‘Simple suggestion for avoiding infinite redirects’ is closed to new replies.