• Resolved jrgalia

    (@jrgalia)


    We use rankmath to generate llms.txt. It works if NextGEN Gallery plugin is deactivated. When active, llms.txt got “too many redirect issue”.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Mihai

    (@mceban)

    Hi @jrgalia,

    Thanks for the report!

    We were able to replicate the issue on our end and will be investigating the cause. In the meantime, you might want to reach out to the RankMath support team to see if they have any insights.

    Best regards,
    Mihai

    Thread Starter jrgalia

    (@jrgalia)

    do you have update on this matter?

    Plugin Support Mihai

    (@mceban)

    Hi @jrgalia ,

    Sorry for the delayed reply here. It appears to be a conflict caused by NextGEN Gallery own template redirection conflicting with RankMath.

    A report has been created about this issue to notify our development team about it. I apologize for the inconvenience in the meantime. I can’t currently provide an ETA for when a fix will be released. However, I’m taking note of this thread and I’ll make sure to send you an update when an update that fixes this issue is released.

    As a possible workaround you can try using this PHP code snippet:

    <?php 
    /**
    * Temporary fix for NextGEN Gallery Router redirect conflicts
    *
    * This snippet prevents redirect loops when using third-party plugins
    * that also handle template_redirect hooks (like LLMS, etc.)
    *
    * Remove this code after updating to the next version of NextGEN Gallery
    */

    // Prevent NextGEN Gallery Router from interfering with third-party redirects
    add_action( 'init', function() {
    // Check if we're on a URL that might conflict with third-party plugins
    $request_uri = $_SERVER['REQUEST_URI'] ?? '';

    // List of patterns that commonly conflict with third-party plugins
    $conflict_patterns = [
    '/llms.txt',
    ];

    // Check if current URL matches any conflict patterns
    $has_conflict = false;
    foreach ( $conflict_patterns as $pattern ) {
    if ( strpos( $request_uri, $pattern ) !== false ) {
    $has_conflict = true;
    break;
    }
    }

    // If there's a potential conflict, remove NextGEN's template_redirect actions
    if ( $has_conflict ) {
    // Remove NextGEN Router's template_redirect hook
    remove_action( 'template_redirect', [ 'Imagely\NGG\Util\Router', 'restore_request_uri' ], 1 );

    // Also remove the hook from any existing Router instances
    global $wp_filter;
    if ( isset( $wp_filter['template_redirect'] ) ) {
    foreach ( $wp_filter['template_redirect']->callbacks as $priority => $callbacks ) {
    foreach ( $callbacks as $callback_id => $callback ) {
    if ( is_array( $callback['function'] ) &&
    is_object( $callback['function'][0] ) &&
    get_class( $callback['function'][0] ) === 'Imagely\NGG\Util\Router' &&
    $callback['function'][1] === 'restore_request_uri' ) {
    remove_action( 'template_redirect', $callback['function'], $priority );
    }
    }
    }
    }
    }
    }, 20 ); // Run after NextGEN has registered its hooks

    // Alternative approach: Use a more targeted fix for specific plugins
    add_action( 'template_redirect', function() {
    // Check for specific third-party plugin endpoints
    if ( get_query_var( 'llms_txt' ) === 1 ) {
    // Remove NextGEN's redirect handling for LLMS txt endpoint
    remove_action( 'template_redirect', [ 'Imagely\NGG\Util\Router', 'restore_request_uri' ], 1 );
    return;
    }

    // Add more specific checks here for other plugins if needed
    // Example for other common endpoints:
    // if ( strpos( $_SERVER['REQUEST_URI'], '/your-plugin-endpoint' ) !== false ) {
    // remove_action( 'template_redirect', [ 'Imagely\NGG\Util\Router', 'restore_request_uri' ], 1 );
    // return;
    // }
    }, 1 ); // Run at priority 1, same as NextGEN but after it's registered

    For the most beginner-friendly option to add custom code like this to your site, I’d recommend using the WPCode plugin: http://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/. This will protect your code from updates and keep it easy to manage right within your WordPress admin area.

    Please let me know if you have any questions.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘NextGEN Gallery Causes /llms.txt too many redirects’ is closed to new replies.