You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

同一服务器复制WordPress站点后出现资源冲突问题求助

解决WordPress跨文件夹站点资源混淆问题

1. 定义精确的文件系统路径常量

在两个站点的wp-config.php中,除了URL,必须明确指定文件系统的绝对路径常量,彻底避免路径混淆:

// 站点1的wp-config.php配置
define('WP_HOME', 'https://你的站点1域名.com');
define('WP_SITEURL', 'https://你的站点1域名.com');
define('WP_CONTENT_DIR', '/var/www/site1/wp-content'); // 替换为站点1的实际绝对路径
define('WP_CONTENT_URL', 'https://你的站点1域名.com/wp-content');
define('ABSPATH', dirname(__FILE__) . '/'); // 强制指定站点根目录

// 站点2的wp-config.php配置
define('WP_HOME', 'https://你的站点2域名.com');
define('WP_SITEURL', 'https://你的站点2域名.com');
define('WP_CONTENT_DIR', '/var/www/site2/wp-content'); // 替换为站点2的实际绝对路径
define('WP_CONTENT_URL', 'https://你的站点2域名.com/wp-content');
define('ABSPATH', dirname(__FILE__) . '/'); // 强制指定站点根目录

如果不知道绝对路径,可以在站点根目录新建get-path.php,写入<?php echo dirname(__FILE__) . '/'; ?>,访问该文件即可获取。

2. 彻底清理数据库中的旧路径残留

即使使用不同数据库,Duplicator复制时可能仍有未替换的路径残留,需手动执行SQL替换:

  • 登录各站点的数据库管理工具(如phpMyAdmin)
  • 执行以下SQL(替换表前缀、旧路径/域名、新路径/域名):
-- 替换选项表中的路径
UPDATE wp_options SET option_value = REPLACE(option_value, '旧站点路径/域名', '新站点路径/域名') 
WHERE option_name IN ('home', 'siteurl', 'upload_path', 'fileupload_url', 'wp_cron');

-- 替换文章内容中的旧链接
UPDATE wp_posts SET post_content = REPLACE(post_content, '旧站点路径/域名', '新站点路径/域名');

-- 替换文章元数据中的旧路径
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '旧站点路径/域名', '新站点路径/域名');

3. 检查服务器虚拟主机配置

确保Apache/Nginx的虚拟主机配置完全隔离两个站点,根目录指向各自文件夹:

Apache示例

<VirtualHost *:443>
    ServerName 站点1域名.com
    DocumentRoot /var/www/site1
    <Directory /var/www/site1>
        AllowOverride All
        Require all granted
    </Directory>
    # SSL等其他配置...
</VirtualHost>

<VirtualHost *:443>
    ServerName 站点2域名.com
    DocumentRoot /var/www/site2
    <Directory /var/www/site2>
        AllowOverride All
        Require all granted
    </Directory>
    # SSL等其他配置...
</VirtualHost>

Nginx示例

server {
    listen 443 ssl;
    server_name 站点1域名.com;
    root /var/www/site1;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    # PHP、SSL等其他配置...
}

server {
    listen 443 ssl;
    server_name 站点2域名.com;
    root /var/www/site2;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    # PHP、SSL等其他配置...
}

4. 清除所有层级缓存

  • 清空两个站点的WordPress缓存插件(如果启用)
  • 重启服务器的OPcache/APC缓存服务
  • 用浏览器无痕模式测试,避免本地缓存干扰

5. 验证Duplicator复制配置

重新检查Duplicator的复制过程,确保在复制向导中勾选了**“替换所有URL和路径”**选项,或手动完成路径替换,避免旧站点配置残留。

内容的提问来源于stack exchange,提问作者Endriu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:05:20