5

基本上正如标题所说,我在反向代理后面有一个 wp。假设域是,wordpress 是 * *** /blog 以下是允许它以这种方式工作的 wp-config.php 编辑:

define('.ADMIN_COOKIE_PATH.', '/blog');
define('.COOKIE_DOMAIN.', 'www.***.com');
define('.COOKIEPATH.', '/blog');
define('.SITECOOKIEPATH.', '.');


if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
        $_SERVER['REMOTE_ADDR'] = $list[0];
  }
define('DOMAIN_CURRENT_SITE', 'https://www.***.com/blog');
define('WP_HOME','https://www.***.com/blog');
define('WP_SITEURL','https://www.***.com/blog');
$_SERVER['REMOTE_ADDR'] = 'https://www.***.com/blog';
$_SERVER['HTTP_HOST'] = 'www.***.com/blog';
$_SERVER[ 'SERVER_ADDR' ] = 'www.***.com/blog';


define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
       $_SERVER['HTTPS']='on';

$_SERVER['REQUEST_URI'] = str_replace("https://www.***.com/wp-admin",
                                      "https://www.***.com/blog/wp-admin",
                                      $_SERVER['REQUEST_URI']);

现在,这一切都很完美,但是当我在管理面板的某些地方时,让我们说评论,如果我提交表单,WP 会转到* /wp-admin 而不是* /blog/wp-admin 并崩溃到 404。

更新

尝试了 VHost 方法,将其添加到我的 httpd.conf

Listen 80 <VirtualHost *:80> 
  DocumentRoot /var/www/wp-admin 
  ServerName https://***/blog/wp-admin 

# Other directives here 
</VirtualHost> 

但奇怪的是,每当我在此之后去 /blog 时都会出现重定向循环

我该如何解决?

4

1 回答 1

5

$_SERVER['REQUEST_URI'] do not contains the full URL, so you should replace only /wp-admin/. Given your example:

 $_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",
                                            $_SERVER['REQUEST_URI']);
于 2015-05-09T03:04:24.773 回答