I just had the same issue and for me the reason wasn't broken plugin code. To find this one, I really needed to debug the wp_redirect code in
wp-includes/pluggable.php:1246 and add the following lines at the beginning of the function:
Usually, you may inject such code via a filter like
wp_redirect but that didn't work for me since the error occurred before my theme or plugin code was loaded by WordPress. Now, I observed the response body of my AJAX request in the developer network tools of my browser. You may also use
trigger_error(wp_debug_backtrace_summary()) and observe the stacktrace in
wp-content/debug.log (if you enable the debug log).
My issue was naming a file in my theme
admin.php and importing it with
include_once("admin.php");. Strangely, the requirement logic starts looking for a file with that name in the upper parent folder,s and thus, it loada
wp-admin/admin.php leading to an authentication error and finally my erroneous redirect.
And here goes the solution to my particular issue:
// Instead of: include_once('admin.php');
include_once(dirname(__FILE__) . 'admin.php');
I guess, there are many ways to have such redirect issues. Hopefully, my problem-solving method helps other people out there with their problems.