0

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 Answer 1

1

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 */
?>
Sign up to request clarification or add additional context in comments.

6 Comments

forgive me- would I put this in my theme's functions.php?
You should write a plugin for wordpress to use the function this way you not changing core files. There are lots of examples out there of how to write a plug in or find a simple plugin like hello world rename it and add the function. @mydoglixu codex.wordpress.org/Pluggable_Functions codex.wordpress.org/Writing_a_Plugin
I don't mean to say that I'd change core files, but in my wp-content/themes/themename/functions.php. Is that a good enough place for this?
No you don't want to use theme functions theme functions are not used in admin and that is where you having problems I will add the code above you can use as a plugin
This didn't wind up fixing my particular problem, but this one did: stackoverflow.com/questions/34090577/…. However, thanks very much for the info- I learned more about wordpress from it!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.