【问题标题】:Getting wordpress to work with the same wp-config.php on wamp localhost and live server让 wordpress 在 wamp localhost 和实时服务器上使用相同的 wp-config.php
【发布时间】:2019-07-12 08:53:29
【问题描述】:

为了方便我的 localhost -> 实时服务器迁移,我希望我的本地 Wordpress 站点(由 wamp 提供支持)使用与我在线的完全相同的 wp-config.php 文件:

//Define new directory path
define ('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME);

 //Define new directory URL
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME);

到目前为止,这不起作用,所以我必须使用其他配置:

define( 'WP_CONTENT_DIR', 'C:\wamp64\www\domain.dev\content' );
define( 'WP_CONTENT_URL', 'http://localhost/domain.dev/content' );

我应该怎么做才能使用第一个配置?

【问题讨论】:

    标签: wordpress wamp


    【解决方案1】:

    您可以使用php $_SERVER 数组来获取主机$_SERVER['HTTP_HOST'] 并比较它是开发环境还是实时环境。

    因此,您的 wp-config.php 文件将如下所示:

    $cur_env = $_SERVER['HTTP_HOST'];
    
    if($cur_env == 'localhost'){ //Or could be '127.0.0.1' - Or whatever your wamp base url is set.
        define( 'WP_CONTENT_DIR', 'C:\wamp64\www\domain.dev\content' );
        define( 'WP_CONTENT_URL', 'http://localhost/domain.dev/content' );
    }else{
        define('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME);
        define('WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-02-07
      • 2020-12-22
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 2012-07-26
      • 2019-04-23
      • 2015-10-31
      • 1970-01-01
      相关资源
      最近更新 更多