WordPress Infinite 301 Redirect Loop

Depending on your current environment setup, there’s a chance you’ll come across an infinite 301 redirect loop when installing WordPress.¬† If you do, there’s a simple temporary solution to fix the problem.

Place this¬†line of code in your theme’s functions.php file.

remove_filter( 'template_redirect', 'redirect_canonical' );

This will prevent the redirection for feeds, trackbacks, searches, comment popup, and admin URLs.

I wouldn’t recommend this as a permanent solution, but it’ll definitely buy you some time while your trying to figure out the real issue.

I'm a Long Island, NY based Web and App Designer.

  • Hudson Atwell

    I’m in a situation where this is the solution to prevent an infinite redirect when I call:

    $test = get_queried_object();

    or

    $test = $wp_query->get_queried_object_id();

    in the ‘wp’ action hook.

    I just don’t understand how the two could be related, and if this is a temporary fix, what functionality would we be losing?

    • allankiezel

      It has some detrimental effects when it comes to SEO, and I believe there could be some issues when using SSL certificates, but I’m not positive on that.

      I started having the redirect issue when I converted to NGINX from Apache. This helped me with it until I got the server configured properly.

      Thanks for the comment!