将 wordpress 站点从实时设置为本地,URL 不起作用

Setup wordpress site from live to local, URLs are not working

3/26:我在实时服务器上创建了 Wordpress 网站。我下载了一个副本到我的 XAMPP 服务器。我导出了数据库并创建了一个本地数据库。我修改了 wp-config.php 文件以连接到它。一切正常。但是,我无法使用导航栏中的任何链接,也无法打开任何页面和帖子。所有这些超链接都有使用实时服务器域名的绝对地址。我可以添加目录路径并转到本地主机下的“/index.php”,但所有其他路径都是开放式的,没有文件名,它们不起作用。如果我不使用 "index.php" 而只有一个“/”,它将不会转到主页。对于主页,如果我省略 "index.php" 文件名,它将具有 header 和导航栏并显示 "Oops! That page can’t be found." 如果我使用指向其他任何内容的开放式链接,它将显示 "Error establishing a database connection."

3/27:非常感谢大家的回复!我安装了一个尚未使用的插件,名为 "Velvet Blues Update URLs." 我会试一试。我也有 "All-in-One WP Migration" 和 "Duplicator,",但该网站的大小超过 600mb,因此这些网站的免费版本将无法使用。

您可以在本地安装中使用临时 URL,方法是编辑 wp-config.php 并定义 WP_HOMEWP_SITEURL,例如

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

我假设您也在本地安装中克隆了数据库。如果是这种情况,您必须更新数据库中的所有条目以匹配本地安装的 url。

如果实时站点名为 http://example.com you should find every occurrence of it and change it to http://localhost/my_install

UPDATE wp_options SET option_value = replace(option_value, 'http://example.com', 'http://localhost/my_install') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = REPLACE (guid, 'http://example.com', 'http://localhost/my_install');

UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://example.com', 'http://localhost/my_install');

UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://example.com', 'http://localhost/my_install');

UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="http://example.com', 'src="http://localhost/my_install');

UPDATE `wp_posts` SET `guid` =  REPLACE( `guid` , 'http://example.com' , 'http://localhost/my_install' ) WHERE `post_type` = 'attachment';

UPDATE wp_posts SET  guid = REPLACE (guid, 'http://example.com', 'http://localhost/my_install') WHERE post_type = 'attachment';

这个 SQL 查询应该可以为您做到这一点。只需将虚拟数据替换为实际数据即可。并重新保存永久链接结构(设置 -> 永久链接)。

将 WP 从本地移动到实时服务器一直是一个令人头疼的问题。为此,这是我经常使用的插件,再也没有遇到任何问题。 https://fr.wordpress.org/plugins/duplicator/

您应该使用它来迁移您的网站。顺便说一下,如果您不使用该插件,您可以在移动到 Live Server DB 之前在 DB 文件中找到替换所有 URL。