2016-12-20 20:59
浏览 62


im trying to connect my local wordpress install to a db on a domain i own using the code provided here:

define('WP_CACHE', true); $currenthost = $_SERVER['HTTP_HOST'];
$mypos = strpos($currenthost, 'localhost/wpdir');
if ($mypos === false) { 
} else { 

with the above config i can open the site locally, it loads the navigation and recent post names correctly, so the db-connection seems to work. i cannot use links and pages are not found though.

if i add my /wpDir/ to the define('WP_HOME'... and/or strpos($currenthost,... it gets redirected to http://localhost/wpDir/home/ (as it should) but i get an URL not found error.

my localhost dir is standard /var/www/html this is where my local wordpress installations are.

any ideas how to fix this?

update: i am back to working on this and it would really help a lot if i could manage to use the remote database for my local testing i think it may be some kind of url rewriting problem but all my efforts to find a solution did not work...

图片转代码服务由CSDN问答提供 功能建议

我尝试使用此处提供的代码将我的本地wordpress安装连接到我拥有的域上的数据库: database-with-local-wordpress-instance

  define('WP_CACHE',true);  $ currenthost = $ _SERVER ['HTTP_HOST']; 
 $ mypos = strpos($ currenthost,'localhost / wpdir'); 
if($ mypos === false){
 define('WP_HOME','http:  //');
} else {
 define('WP_HOME','http:// localhost'); 
 define('WP_SITEURL','http:// localhost / wpDir /'); 

使用上面的配置我可以在本地打开网站,它正确加载导航和最近的帖子名称,所以db-connection似乎可以工作。 i不能使用链接和页面是 但是没有找到。

如果我将 / wpDir / 添加到 define('WP_HOME'... 和/或< code> strpos($ currenthost,... 它被重定向到 http:// localhost / wpDir / home / (应该如此)但我得到一个URL not found错误。< / p>

我的localhost目录是标准的 / var / www / html 这是我本地wordpress安装的地方。

任何想法 如何解决这个问题?

更新:我重新开始工作,如果我可以设法使用远程数据库进行本地测试,那将真的有很大帮助 i认为它可能 是某种网址重写问题,但我所有努力寻找解决方案都不起作用......

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhan0562 2017-01-31 09:28

    not sure why it was so hard to find but i managed to do it (another way) basically by following the wp-codex here: using the drop-in method: the code in my db.php file looks like this:

    // paste this in a (new) file, wp-content/db.php
    add_filter ( 'pre_option_home', 'test_localhosts' );
    add_filter ( 'pre_option_siteurl', 'test_localhosts' );
    function test_localhosts( ) {
      if (strcasecmp($_SERVER['REQUEST_URI'], '/localCopyOfSite') == 0
          || strcasecmp(substr($_SERVER['REQUEST_URI'], 0, 17), '/localCopyOfSite/') == 0) {
         return "http://localhost/localCopyOfSite/";
      else return false; // act as normal; will pull main site info from db
    解决 无用
    打赏 举报

相关推荐 更多相似问题