Redirect loop due to capitalization

I have already fixed this problem on my own site by editing the Domain Mapping source code, but I think it should be fixed properly in the plugin.

My multisite installation is using Nginx and I was periodically getting a redirect loop error on one of my client's sites. Then Nginx would cache the redirect loop, causing it to display for everyone. If I purged the cache then visited the site, the problem was always fixed. But then it always came back again at some point.

After much debugging, I realized the problem was due to someone entering in the site URL in all caps (like EXAMPLE.COM instead of example.com). This caused the redirect loop, then Nginx cached the error so it displayed to other people as well.

I fixed this problem by editing the domain-mapping/classes/Domainmap/Module/Mapping.php file.

Line 286: if ( $mapped_url != $current_url )
Edited to: if ( strtolower($mapped_url) != strtolower($current_url) )

  • Vaughan
    • Support/SLS MockingJay

    Hi @ashley,

    I believe this is an actual bug in wordpress 3.9 itself.

    It's related to https://core.trac.wordpress.org/ticket/27866

    However that doesn't help people at moment, as they will need to make sure they use lowercase from now on.

    So, maybe the developers could add the strtolower function in the code to help ease the pain of this issue with 3.9

    I'll let the developer know and hopefully he can address this issue quickly.

    Thanks for the report & the solution you have found.

  • Ashley
    • Flash Drive

    Because right below that the code does a 301 redirect. I knew the blog was being stuck in a 301 redirect loop and this was one of two places in the script that I found that was doing a 301 redirect.

    if ( strtolower($mapped_url) != strtolower($current_url) ) {
    	// strip out any subdirectory blog names
    	$request = str_replace( "/a" . $current_blog->path, "/", "/a" . $_SERVER['REQUEST_URI'] );
    	if ( $request != $_SERVER['REQUEST_URI'] ) {
    		header( "HTTP/1.1 301 Moved Permanently", true, 301 );
    		header( "Location: " . $mapped_url . $request, true, 301 );
    	} else {
    		header( "HTTP/1.1 301 Moved Permanently", true, 301 );
    		header( "Location: " . $mapped_url . $_SERVER['REQUEST_URI'], true, 301 );
    	}
    	exit;
    }

    I was able to trace that it was doing a 301 redirect to itself, and by doing some logging of the current URL and mapped URL, I noticed a few entries where the current URL was the URL in all caps and the mapped URL was the URL in lowercase. PHP recognized those as not equaling each other, so it was triggering the 301 redirect, then it got stuck in a loop since it was redirecting to itself.

  • Sam
    • The Incredible Code Injector

    @Ashley

    That was smart to notice, I was not able to reproduce the issue my my machine probably because i'm on apache.

    Any thanks for it and i'll add it in the next release, although ppl at WP are releasing 3.9.1 soon that tackles the issue in a lower level

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.