Wordpress wp-login redirecting to wrong url when using Forward Rewrite

779 views Asked by At

We have a domain which is https://developer.site.com served on one server. Then, we have https://developer.site.com/blog which goes to an entirely different location, serving up a wordpress site. (Technically speaking this is called a 'forward rewrite.')

The front-end and most of the admin are acting fine, however there are a couple of places where it is redirecting back to a 404 on the other server.

For example:

https://developer.site.com/blog/wp-login.php?action=rp&key=t34T4akjihAB231sCwgJU9TU&login=abcde

This URL redirects to the 404, excluding the /blog part from the URL.

When tracking the site, it appears it goes go to the right url, but then immediately wordpress is sending it to the 404 page, so it's something wrong with wordpress. We have checked and double-checked the domain masking and we're convinced it's all good.

I have found wp_safe_redirect() in the code a few times. This might be the culprit? Maybe something is pulling up the wrong directory structure, leaving off the /blog part internally, but I don't see why that should matter.

1

There are 1 answers

6
chop62 On

You can filter redirects here is what i think will work for you

    add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );
function my_allowed_redirect_hosts($content){
    $content[] = 'blog.example.com';
    $content[] = 'codex.example.com';
    // wrong: $content[] = 'http://codex.example.com';
    return $content;
}

More Info about here https://codex.wordpress.org/Function_Reference/wp_safe_redirect

Copy the following code in your text editor CHANGE THE EXAMPLE HOST DOMAIN LINES and save it as allowed-host-plugin.php put in a folder called allowed-host-plugin and upload it to your plugins directory go to you plugins in admin and activate. That's it should work.

    <?php    
/*
Plugin Name: Allowed Host Plugin
Description: Site specific code changes for allowed host domains no admin change in code below
*/
/* Start Adding Functions Below this Line */
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );

function my_allowed_redirect_hosts($content){
    // Add your allowed hosts below
    $content[] = 'blog.example.com';
    $content[] = 'codex.example.com'; 
    // wrong: $content[] = 'http://codex.example.com';
    return $content;
    }

/* Stop Adding Functions Below this Line */
?>