如何将 WordPress 网站从一个位置复制/传输到另一个位置 [英] How to copy/transfer WordPress sites from one location to another

查看:46
本文介绍了如何将 WordPress 网站从一个位置复制/传输到另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WordPress 的新手,对这个平台印象深刻……直到将我的本地 MAMP wordpress 站点发布到我的生产服务器 - 没有明确和直接的方法可以从一台服务器传输站点到另一个.

I'm new to WordPress and thoroughly impressed with the platform... That is until it came time to publish my local MAMP wordpress site to my production server- There's just no clear and straightforward way to transfer a site from one server to another.

目标:

将完整的 wordpress 网站从一个位置转移到另一个位置,同时保留所有媒体、设置和内容.

Transfer a complete wordpress site from one location to another, while maintaining all media, settings, and content.

现有方法限制:

  • 内置导出/导入功能
    • 不传输主题或设置
    • 添加到当前内容,但不会替换当前文章或清除旧文章.
    • 路径是绝对路径,不会更新,因此新站点中的链接等都已损坏.

    注意:

    codex 提供了这个多步解决方案,但我正在寻找更简单的方法.对于重复传输是不切实际的,例如在发布场景中.

    The codex offers this multi-step solution, but I'm looking for something easier. It's not practical for repeated transfers, like in a publishing scenario.

    推荐答案

    无法避免这样做(据我所知)

    There's no avoiding doing it this way (as far as I know)

    1. 您移动文件
    2. 移动数据库,使用 phpMyAdmin 中的导出/导入
    3. 编辑您的配置(在/wp-config.php 中)以反映新的数据库设置.
    4. 在 phpMyAdmin 中执行以下 SQL:

    更新站点设置的选项:

    UPDATE wp_options SET 
        option_value = replace(option_value, 
                               'http://oldsite.com/path', 
                               'http://spankingnew.com/otherpath') 
    WHERE 
        option_name = 'home' 
    OR 
        option_name = 'siteurl';
    

    同时更新帖子内容和帖子 slugs/url:

    Update the post contents and the post slugs/urls at the same time:

    UPDATE wp_posts SET 
        post_content = replace(post_content, 
                               'http://oldsite.com/path', 
                               'http://spankingnew.com/otherpath'),
        guid = replace(guid, 
                       'http://oldsite.com/path',
                       'http://spankingnew.com/otherpath');
    

    你应该完成..

    当然在此过程中可能还有其他一些问题,但我已经这样做过几次了.

    Of course there might be some other problems along the way, but I've done it this way a few times.

    @Yarin 指出有一种更简单的方法来更新站点 url:只需将 url 设置硬编码到/wp-config.php 中.

    @Yarin pointed out that there is a much easier way to update the site urls: Just harcode the url settings into /wp-config.php.

    在/wp-config.php 中,添加:

    In /wp-config.php, add this:

    define('WP_HOME','http://{my site path}');
    define('WP_SITEURL','http://{my site path}');
    

    无论您导入什么数据,此一劳永逸将自动更新数据库中的所有 url 路径.如果您经常从另一个站点导入数据,这将特别有用,例如在开发到生产的发布场景中.

    This set-and-forget will automatically update all url paths across the database no matter what data you import. It's especially useful if you are constantly importing data from another site, like in a dev-to-production publishing scenario.

    这篇关于如何将 WordPress 网站从一个位置复制/传输到另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆