是的,因为wordpress使用数据库中的服务器地址get_option(\'siteurl\')
和get_option(\'home\')
, 因此,如果您从IP地址访问wordpress,资产(js和css)仍将从localhost/wp/
这意味着127.0.0.1
不是10.0.0.1
获取wordpress动态url的简单方法是在wp配置上定义site\\u url和home\\u url。php函数,用于解析请求并获取wordpress的正确根url
尝试将此脚本添加到
/** Absolute path to the WordPress directory. */
if ( !defined(\'ABSPATH\') )
define(\'ABSPATH\', dirname(__FILE__) . \'/\');
/**
* get home url from absolute path
* @return string url to main site
* [email protected]
*/
function get_dynamic_home_url(){
$base_dir = ABSPATH; // Absolute path
$doc_root = preg_replace("!${_SERVER[\'SCRIPT_NAME\']}$!", \'\', $_SERVER[\'SCRIPT_FILENAME\']);
$base_url = preg_replace("!^${doc_root}!", \'\', $base_dir);
$protocol = empty($_SERVER[\'HTTPS\']) ? \'http\' : \'https\';
$port = $_SERVER[\'SERVER_PORT\'];
$disp_port = ($protocol == \'http\' && $port == 80 || $protocol == \'https\' && $port == 443) ? \'\' : ":$port";
$domain = $_SERVER[\'SERVER_NAME\'];
$home_url = "${protocol}://${domain}${disp_port}${base_url}";
return $home_url;
}
$url = get_dynamic_home_url();
define(\'WP_SITEURL\', $url);
define(\'WP_HOME\', $url);