0

我们有一个域https://developer.site.com在一台服务器上提供服务。然后,我们将https://developer.site.com/blog转到一个完全不同的位置,提供一个 wordpress 站点。(从技术上讲,这称为“前向重写”。)

前端和大多数管理员都表现良好,但是有几个地方重定向回另一台服务器上的 404。

例如:

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

此 URL 重定向到 404,不包括 URL 中的 /blog 部分。

跟踪站点时,它似乎转到了正确的 url,但随后 wordpress 立即将其发送到 404 页面,因此 wordpress 有问题。我们已经检查并再次检查了域掩码,我们确信一切正常。

我在代码中找到了 wp_safe_redirect() 几次。这可能是罪魁祸首?也许有些东西拉错了目录结构,在内部省略了 /blog 部分,但我不明白为什么这很重要。

4

1 回答 1

1

您可以在这里过滤重定向,我认为这对您有用

    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;
}

有关此处的更多信息https://codex.wordpress.org/Function_Reference/wp_safe_redirect

在您的文本编辑器中复制以下代码更改示例主机域并将其保存为 allowed-host-plugin.php 放入名为 allowed-host-plugin 的文件夹中并将其上传到您的插件目录 转到您在管理员中的插件并激活. 那是它应该工作的。

    <?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 */
?>
于 2016-12-17T16:40:47.323 回答