Changing The Site URL 更改站点 URL
On the Settings -> General
screen in a single site installation of WordPress, there are two fields named “WordPress Address (URL)” and “Site Address (URL)”. They are important settings since they control where WordPress is located. These settings control the display of the URL in the admin section of your page, as well as the front end, and are used throughout the WordPress code.
在 WordPress 的单个站点安装的设置 -> 常规
屏幕上,有两个名为 “WordPress 地址 (URL)” 和 “站点地址 (URL)” 的字段。它们是重要的设置,因为它们控制着 WordPress 的位置。这些设置控制 URL 在页面的 admin 部分以及前端的显示,并在整个 WordPress 代码中使用。
- The “Site Address (URL)” setting is the address you want people to type in their browser to reach your WordPress blog.
“站点地址 (URL)”设置是您希望人们在浏览器中输入以访问您的 WordPress 博客的地址。 - The “WordPress Address (URL)” setting is the address where your WordPress core files reside.
“WordPress 地址 (URL)”设置是 WordPress 核心文件所在的地址。
Note: Both settings should include the https:// part and should not have a slash /
at the end.
注意:这两个设置都应包括 https:// 部分,并且末尾不应有斜杠 /
。
Every once in a while, somebody finds a need to manually change (or fix) these settings. Usually, this happens when they change one or both and discover that their site no longer works properly. This can leave the user with no easily discoverable way to correct the problem. This article tells you how to change these settings directly.
每隔一段时间,就会有人发现需要手动更改(或修复)这些设置。通常,当他们更改一个或两个并发现他们的网站不再正常运行时,就会发生这种情况。这可能会使用户无法轻松发现来纠正问题。本文介绍如何直接更改这些设置。
Additional information is presented here for the case where you are moving WordPress from one site to another, as this will also require changing the site URL. You should not attempt to use this additional information if you’re only attempting to correct a “broken” site.
对于您将 WordPress 从一个站点移动到另一个站点的情况,此处提供了其他信息,因为这也需要更改站点 URL。如果您只是尝试更正“损坏的”网站,则不应尝试使用这些附加信息。
Alert! These directions are for single installs of WordPress only. If you are using WordPress MultiSite, you will need to manually edit your database.
警报!这些说明仅适用于 WordPress 的单次安装。如果您使用的是 WordPress MultiSite,则需要手动编辑数据库。
There are four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
有四种简单的方法可以手动更改站点 URL。这些方法中的任何一种都将起作用并执行大致相同的功能。
Edit wp-config.php 编辑wp-config.php
It is possible to set the site URL manually in the wp-config.php
file.
可以在 wp-config.php
文件中手动设置站点 URL。
Add these two lines to your wp-config.php
, where “example.com” is the correct location of your site.
将这两行添加到您的wp-config.php
中,其中 “example.com” 是您网站的正确位置。
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );
This is not necessarily the best fix, it’s just hard-coding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.
这不一定是最好的解决方法,它只是将值硬编码到网站本身中。使用此方法时,您将无法再在 General settings (常规设置) 页面上编辑它们。
Edit functions.php 编辑functions.php
If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.
如果可以通过 FTP 访问站点,则此方法将帮助您快速恢复站点并运行(如果更改了这些值)。
- FTP to the site, and get a copy of the active theme’s functions.php file. You’re going to edit it in a simple text editor and upload it back to the site.
FTP 连接到站点,并获取活动主题的 functions.php 文件的副本。您将在简单的文本编辑器中对其进行编辑,然后将其上传回网站。 - Add these two lines to the file, immediately after the initial
<?php
line:
将以下两行添加到文件中,紧跟在初始<?php
行之后:
update_option( 'siteurl', 'https://example.com' );
update_option( 'home', 'https://example.com' );
Obviously, use your own URL instead of example.com
.
显然,请使用您自己的 URL 而不是 example.com
。
- Upload the file back to your site, in the same location. FileZilla offers a handy “edit file” function to do all of the above rapidly; if you can use that, do so.
将文件上传回您的站点的同一位置。FileZilla 提供了一个方便的“编辑文件”功能来快速完成上述所有作;如果可以使用它,请这样做。 - Load the login or admin page a couple of times. The site should come back up.
加载登录页或管理员页几次。该网站应该会恢复正常。
Important! Do not leave this code in the functions.php
file. Remove them after the site is up and running again.
重要!请勿将此代码保留在 functions.php
文件中。在网站重新启动并运行后删除它们。
Note: If your theme doesn’t have a functions.php
file create a new one with a text editor. Add the <?php
tag and the two lines using your own URL instead of example.com
:
注意:如果您的模板没有 functions.php
文件,请使用文本编辑器创建一个新文件。添加 <?php
标签和两行代码,使用您自己的 URL 而不是 example.com
:
<?php
update_option( 'siteurl', 'https://example.com' );
update_option( 'home', 'https://example.com' );
Upload this file to your theme directory. Remove the lines or remove the file after the site is up and running again.
将此文件上传到您的主题目录。在网站重新启动并运行后删除行或删除文件。
LAN-based site to externally accessible site
基于 LAN 的站点到外部可访问的站点
Here are some additional details that step you through transferring a LAN-based WordPress site into an externally accessible site, as well as enabling editing the wordpress site from inside the LAN.
以下是一些额外的细节,可以指导您将基于 LAN 的 WordPress 网站转移到外部可访问的站点,以及启用从 LAN 内部编辑 WordPress 网站。
Two important keys are router/firewall modifications and the “wait 10+ minutes” after making the changes at the end.
两个重要的关键是路由器/防火墙修改和最后进行更改后的“等待 10+ 分钟”。
- Using SSH to log into your server (nano is a server preinstalled text editor):
使用 SSH 登录您的服务器(nano 是服务器预装的文本编辑器):
$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
- Add lines just after
<?php
在<?php
之后添加行
update_option( 'siteurl', 'https://example.com:port/yourblog');
update_option( 'home', 'https://example.com:port/yourblog');
- Refresh your web browser using your external site URL:
使用外部站点 URL 刷新 Web 浏览器:
https://example.com:port/yourblog
https://example.com:port/yourblog (英文)$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
- Remove those lines you just added (or comment them out)
删除您刚刚添加的那些行(或注释掉它们) -
Access your router, these steps are for pfSense, other routers should have similar settings to look for/watch out for)
访问您的路由器,这些步骤适用于 pfSense,其他路由器应该有类似的设置来查找/注意) -
Add to firewall/nat table a line like this
在 firewall/nat 表中添加一行,如下所示
wan/tcp/port/LAN.server.IP/80
wan/tcp/端口/LAN.server.IP/80
- Add to firewall/rules table a line like this:
在 firewall/rules 表中添加如下行:
tcp/*/port/LAN.server.IP/port/*
- Uncheck the box at System/advanced/network address translation/Disable NAT Reflection
取消选中 System/advanced/network address translation/Disable NAT Reflection 中的框
"Disables the automatic creation of NAT redirect rules for access to your public IP addresses from within your internal networks. Note: Reflection only works on port forward type items and does not work for large ranges > 500 ports."
- Then go do something for ten minutes and when you get back see if the external url https://example.com:port/yourblog from a LAN browser brings the page up correctly.
然后去做某事十分钟,当你回来时,看看来自 LAN 浏览器的外部 url https://example.com:port/yourblog 是否正确地打开了页面。
Relocate method 重定位方法
WordPress supports an automatic relocation method intended to be a quick assist to getting a site working when relocating a site from one server to another.
WordPress 支持自动重新定位方法,旨在在将站点从一台服务器重新定位到另一台服务器时快速帮助站点正常工作。
Code function Code 函数
When RELOCATE has been defined as true in wp-config.php
(see next chapter), the following code in wp-login.php
will take action:
当 RELOCATE 在 wp-config.php
中定义为 true 时(请参阅下一章),wp-login.php
中的以下代码将执行作:
if ( defined( 'RELOCATE' ) AND RELOCATE ) {
// Move flag is set
if ( isset( $_SERVER['PATH_INFO'] ) AND ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], "", $_SERVER['PHP_SELF'] );
$url = dirname( set_url_scheme( 'https://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
if ( $url != get_option( 'siteurl' ) )
update_option( 'siteurl', $url );
}
Steps 步骤
- Edit the
wp-config.php
file.
编辑wp-config.php
文件。 - After the “define” statements (just before the comment line that says “That’s all, stop editing!”), insert a new line, and type:
define('RELOCATE',true);
在“define”语句之后(就在写着“That’s all, stop editing!”的注释行之前),插入新行,然后键入:define('RELOCATE',true);
- Save your
wp-config.php
file.
保存wp-config.php
文件。 - Open a web browser and manually point it to
wp-login.php
on the new server. For example, if your new site is at https://www.example.com, then type https://www.example.com/wp-login.php into your browser’s address bar.
打开 Web 浏览器并手动将其指向新服务器上的wp-login.php
。例如,如果您的新站点位于 https://www.example.com,请在浏览器的地址栏中键入 https://www.example.com/wp-login.php。 - Login as per normal. 照常登录。
- Look in your web browser’s address bar to verify that you have, indeed, logged in to the correct server. If this is the case, then in the Admin back-end, navigate to
Settings > General
and verify that both the address settings are correct. Remember to Save Changes.
查看 Web 浏览器的地址栏,以验证您确实已登录到正确的服务器。如果是这种情况,请在 Admin 后端导航到设置 > 常规
并验证两个地址设置是否正确。记得保存更改。 - Once this has been fixed, edit
wp-config.php
and either completely remove the line that you added (delete the whole line), comment it out (with//
) or change the true value to false if you think it’s likely you will be relocating again.
修复此问题后,编辑wp-config.php
并完全删除您添加的行(删除整行),将其注释掉(使用),或者如果您认为可能会再次重新定位,请将 true 值更改为 false。
Note: When the RELOCATE
flag is set to true, the Site URL will be automatically updated to whatever path you are using to access the login screen. This will get the admin section up and running on the new URL, but it will not correct any other part of the setup. You’ll still need to alter those manually.
注意:当 RELOCATE
标志设置为 true 时,站点 URL 将自动更新为您用于访问登录屏幕的任何路径。这将使 admin 部分在新 URL 上启动并运行,但不会更正设置的任何其他部分。您仍然需要手动更改这些内容。
Important! Leaving the RELOCATE constant in your wp-config.php
file is insecure, as it allows an attacker to change your site URL to anything they want in some configurations. Always remove the RELOCATE line from wp-config.php
after you’re done.
重要!在 wp-config.php
文件中保留 RELOCATE 常量是不安全的,因为它允许攻击者在某些配置中将您的站点 URL 更改为他们想要的任何内容。完成后,请务必从 wp-config.php
中删除 RELOCATE 行。
Changing the URL directly in the database
直接在数据库中更改 URL
If you know how to access phpMyAdmin on your host, then you can edit these values directly to get your site up and running again.
如果您知道如何在主机上访问 phpMyAdmin,那么您可以直接编辑这些值以使您的网站重新启动并运行。
- Backup your database and save the copy off-site.
备份您的数据库并异地保存副本。 - Login to phpMyAdmin.
登录到 phpMyAdmin。 - Click the link to your Databases.
单击指向 Databases (数据库) 的链接。 - A list of your databases will appear. Choose the one that is your WordPress database.
将显示您的数据库列表。选择您的 WordPress 数据库。 - All the tables in your database will appear on the screen.
数据库中的所有表都将显示在屏幕上。 - From the list, look for
wp_options
. Note: The table prefix ofwp_
may be different if you changed it when installing.
从列表中,查找wp_options
。注意:如果您在安装时更改了wp_
的表前缀,则表前缀可能会有所不同。 - Click on the small icon indicated as Browse.
单击标记为 Browse(浏览)的小图标。 - A screen will open with a list of the fields within the wp_options table.
将打开一个屏幕,其中包含 wp_options 表中的字段列表。 - Under the field option_name, scroll down and look for
siteurl
.
在字段 option_name 下,向下滚动并查找siteurl
。 - Click the Edit Field icon which usually is found at the far left at the beginning of the row.
单击 Edit Field 图标,该图标通常位于行开头的最左侧。 - The Edit Field window will appear.
此时将出现 Edit Field (编辑字段) 窗口。 - In the input box for option_value, carefully change the URL information to the new address.
在 option_value 的输入框中,小心地将 URL 信息更改为新地址。 - Verify this is correct and click Go to save the information.
验证此内容是否正确,然后单击 Go 以保存信息。 - You should be returned to your
wp_options
table.
您应该返回到wp_options
表。 - Look for the home field in the table and click Edit Field. Note: There are several pages of tables inside
wp_options
. Look for the > symbol to page through them.
在表中查找 home 字段,然后单击 Edit Field (编辑字段)。注意:wp_options
中有几页表格。查找 > 符号以翻阅它们。 - In the input box for option_value, carefully change the URL information to the new address.
在 option_value 的输入框中,小心地将 URL 信息更改为新地址。 - Verify this is correct and click Go to save the information.
验证此内容是否正确,然后单击 Go 以保存信息。
Moving Sites 移动站点
When moving sites from one location to another, it is sometimes necessary to manually modify data in the database to make the new site URL information to be recognized properly. Many tools exist to assist with this, and those should generally be used instead of manual modifications.
将站点从一个位置移动到另一个位置时,有时需要手动修改数据库中的数据,以便正确识别新站点 URL 信息。有许多工具可以帮助实现这一点,通常应该使用这些工具而不是手动修改。
This is presented here as information only. This data may not be complete or accurate.
此处仅作为信息提供。这些数据可能不完整或不准确。
You should read the Moving WordPress article first, if attempting to move WordPress from one system to another.
如果尝试将 WordPress 从一个系统移动到另一个系统,您应该先阅读移动 WordPress 一文。
Altering Table Prefixes 更改表前缀
Like many WordPress administrators, you may be running several WordPress installations off of one database using various wp-config.php
hacks. Many of these hacks involve dynamically setting table prefixes, and if you do end up altering your table prefix, you must update several entries within the prefix_usermeta
table as well.
与许多 WordPress 管理员一样,您可能正在使用各种 wp-config.php
技巧从一个数据库运行多个 WordPress 安装。其中许多 hack 都涉及动态设置表前缀,如果您最终更改了表前缀,则还必须更新 prefix_usermeta
表中的多个条目。
As in the above section, remember that SQL changes are permanent and so you should back up your database first:
如上一节所示,请记住 SQL 更改是永久性的,因此您应该首先备份数据库:
If you are changing table prefixes for a site, then remember to alter the table prefix in the usermeta tables as well. This will allow the new site to properly recognize user permissions from the old site.
如果要更改站点的表前缀,请记住还要更改 usermeta 表中的表前缀。这将允许新站点正确识别来自旧站点的用户权限。
UPDATE `newprefix_usermeta` SET `meta_key` = REPLACE( `meta_key` , 'oldprefix_', 'newprefix_' );
Changing Template Files 更改模板文件
In your WordPress Theme, open each template file and search for any manually entered references to your old domain name and replace it with the new one. Look for specific hand-coded links you may have entered on the various template files such as the sidebar.php
and footer.php
. WordPress uses a template tag called bloginfo()
to automatically generate your site address from information entered in your Administration > Settings > General panel. The tag in your template files will not have to be modified.
在您的 WordPress 主题中,打开每个模板文件并搜索任何手动输入的对旧域名的引用,并将其替换为新域名。查找您可能在各种模板文件(如 sidebar.php
和 footer.php
)上输入的特定手动编码链接。WordPress 使用一个名为 bloginfo()
的模板标签,根据在“管理>设置”>“常规”面板中输入的信息自动生成您的站点地址。模板文件中的标签不必修改。
Changing the Config file 更改 Config 文件
You will need to update your WordPress configuration file if your database has moved or changed in certain ways.
如果您的数据库以某种方式移动或更改,您将需要更新您的 WordPress 配置文件。
- You will only need to modify the config file if:
只有在以下情况下,您才需要修改配置文件:- your database has moved to another server and is not running on your localhost
您的数据库已移至另一台服务器,并且未在您的本地主机上运行 - you have renamed your database
您已重命名数据库 - you have changed the database user name
您已更改数据库用户名
- your database has moved to another server and is not running on your localhost
- Make a backup copy of your
wp-config.php
file.
创建wp-config.php
文件的备份副本。 - Open the
wp-config.php
file in a text editor.
在文本编辑器中打开wp-config.php
文件。 - Review its contents. In particular, you are looking for the database host entry.
查看其内容。特别是,您正在查找数据库主机条目。 - Save the file. 保存文件。
- At this point, your WordPress blog should be working.
此时,您的 WordPress 博客应该可以正常工作。
Verify the Profile 验证配置文件
- In your Administration > Settings > General panel, you will verify that the changes you made in Changing the URL above, are correct.
在 Administration > Settings > General(常规)面板中,您将验证您在上述更改 URL 中所做的更改是否正确。 - Verify that the reference in your WordPress Address (URL) contains the new address.
验证 WordPress 地址 (URL) 中的引用是否包含新地址。 - Verify that the reference in your Site Address (URL) contains the new address.
验证您的站点地址 (URL) 中的引用是否包含新地址。 - If you have made changes, click Save Changes.
如果您已进行更改,请单击 Save Changes。
Changing the .htaccess file
更改 .htaccess 文件
After changing the information in your Administration > Settings > General panel, you will need to update your .htaccess file if you are using Permalinks or any rewrites or redirects.
在“管理 > 设置”> “常规”面板中更改信息后,如果您使用的是永久链接或任何重写或重定向,则需要更新 .htaccess 文件。
- Make a backup copy of your
.htaccess
file. This is not a recommendation but a requirement.
备份.htaccess
文件。这不是建议,而是要求。 - Open the
.htaccess
file in a text editor.
在文本编辑器中打开.htaccess
文件。 - Review its contents, looking for any custom rewrites or redirects you entered. Copy these to another text file for safe keeping.
查看其内容,查找您输入的任何自定义重写或重定向。将这些文件复制到另一个文本文件以便妥善保管。 - Close the file. 关闭文件。
- Follow the instructions on the Permalinks SubPanel for updating your Permalinks to the
.htaccess
file.
按照 Permalinks SubPanel 上的说明更新指向.htaccess
文件的永久链接。 - Open the new
.htaccess
file and check to see if your custom rewrites and redirects are still there. If not, copy them from the saved file and paste them into the new.htaccess
file.
打开新的.htaccess
文件并检查您的自定义重写和重定向是否仍然存在。如果没有,请从保存的文件中复制它们并将其粘贴到新的.htaccess
文件中。 - Make any changes necessary in those custom rewrites and redirects to reflect the new site address.
对这些自定义重写和重定向进行任何必要的更改,以反映新的站点地址。 - Save the file. 保存文件。
- Test those redirects to ensure they are working.
测试这些重定向以确保它们正常工作。
If you make a mistake, you can Restore Your Database from your backup and try this again. So make sure it is right the first time.
如果您犯了错误,您可以从备份中恢复您的数据库,然后重试。因此,请确保第一次就正确无误。
Additional items of note 其他注意事项
There are other things you may wish to change in order to correct URLs when moving sites.
在移动网站时,您可能希望更改其他内容以更正 URL。
- Images link: image links are stored in “post_content” in the
wp_posts
table. You can use the similar code above to update image links.
图片链接:图片链接存储在wp_posts
表中的 “post_content” 中。您可以使用上面的类似代码来更新图像链接。 - wp_options: Besides the “siteurl” and “home” items mentioned above, there are other option_value that also need revision, such as “upload path”, and some plugin items (depends on what you’ve installed, such as widgets, stats, DMSGuestbook, sitemap, etc.)
wp_options:除了上面提到的 “siteurl” 和 “home” 项外,还有其他option_value也需要修改,比如 “upload path”,还有一些插件项(取决于你安装了什么,比如 widgets、stats、DMSGuestbook、sitemap 等) - To fix widgets that contain outdated URL’s, you may edit them in Dashboard / Appearance / Widgets.
要修复包含过时 URL 的小部件,您可以在 Dashboard / Appearance / Widgets 中编辑它们。 - Do a FULL database search for any items left. MAKE SURE you know what you are changing and go through each item for possible improper replacement.
对剩余的任何项目执行 FULL 数据库搜索。确保您知道要更改的内容,并仔细检查每个项目以查找可能的不当替换。 - If you a running a network / have multiple sites, you will need to replace instances of the URL in the database. They are stored in many tables, including each one of the sites (blogs). Be careful in what you replace and be sure you know the meaning of the field before changing it. See the Important GUID note below for an example of what not to change.
如果您正在运行一个网络/拥有多个站点,则需要替换数据库中的 URL 实例。它们存储在许多表中,包括每个站点(博客)。请小心替换的内容,并确保在更改字段之前了解字段的含义。请参阅下面的重要 GUID 说明,了解不应更改的内容的示例。 - Note: If you find your old URL in the database options table under
dashboard_incoming_links
, you can ignore or delete that option. It’s unused since WP 3.8.
注意:如果您在dashboard_incoming_links
下的数据库选项表中找到旧 URL,则可以忽略或删除该选项。自 WP 3.8 以来未使用。
Important GUID Note 重要 GUID 说明
When doing the above and changing the URLs directly in the database, you will come across instances of the URL being located in the “guid” column in the wp_posts
tables. It is critical that you do NOT change the contents of this field.
在执行上述作并直接在数据库中更改 URL 时,您将遇到位于 wp_posts
表中的“guid”列中的 URL 实例。切勿更改此字段的内容,这一点至关重要。
The term “GUID” stands for “Globally Unique Identifier”. It is a field that is intended to hold an identifier for the post which a) is unique across the whole of space and time and b) never, ever changes. The GUID field is primarily used to create the WordPress feeds.
术语“GUID”代表“全局唯一标识符”。它是一个字段,旨在保存帖子的标识符,该标识符 a) 在整个空间和时间中是唯一的,并且 b) 永远不会改变。GUID 字段主要用于创建 WordPress 源。
When a feed-reader is reading feeds, it uses the contents of the GUID field to know whether or not it has displayed a particular item before. It does this in one of various ways, but the most common method is simply to store a list of GUID’s that it has already displayed and “marked as read” or similar.
当源读取器读取源时,它使用 GUID 字段的内容来了解它之前是否显示过特定项目。它以多种方式之一执行此作,但最常见的方法是简单地存储已显示并“标记为已读”或类似的 GUID 列表。
Thus, changing the GUID will mean that many feedreaders will suddenly display your content in the user’s reader again as if it was new content, possibly annoying your users.
因此,更改 GUID 将意味着许多 FeedReader 将突然再次在用户的阅读器中显示您的内容,就像它是新内容一样,这可能会惹恼您的用户。
In order for the GUID field to be “globally” unique, it is an accepted convention that the URL or some representation of the URL is used. Thus, if you own example.com
, then you’re the only one using example.com
and thus it’s unique to you and your site. This is why WordPress uses the permalink, or some form thereof, for the GUID.
为了使 GUID 字段“全局”唯一,使用 URL 或 URL 的某种表示形式是一种公认的约定。因此,如果您拥有 example.com
,那么您是唯一使用 example.com
的人,因此它对您和您的网站来说是独一无二的。这就是 WordPress 对 GUID 使用永久链接或其某种形式的原因。
However, the second part of that is that the GUID must never change. Even if you shift domains around, the post is still the same post, even in a new location. Feed readers being shifted to your new feeds when you change URLs should still know that they’ve read some of your posts before, and thus the GUID must remain unchanged.
但是,第二部分是 GUID 绝不能更改。即使您移动域,该帖子仍然是同一篇帖子,即使在新位置也是如此。当您更改 URL 时,被转移到新源的 Feed 读者仍应知道他们之前已经阅读了您的一些文章,因此 GUID 必须保持不变。
Never, ever, change the contents of the GUID column, under any circumstances.
在任何情况下,永远不要更改 GUID 列的内容。
If the default uploads folder needs to be changed to a different location, then any media URLs will need to be changed in the post_content
column of the posts table. For example, if the default uploads folder is changing from wp-content/uploads
to images
:
如果需要将默认 uploads 文件夹更改为其他位置,则需要在 posts 表的 post_content
列中更改任何媒体 URL。例如,如果默认 uploads 文件夹从 wp-content/uploads
更改为 images
:
UPDATE wp_posts SET post_content = REPLACE(post_content,'www.domain.com/wp-content/uploads','www.domain.com/images');
Multi-site notes 多站点注释
See Moving WordPress Multisite
请参阅移动 WordPress 多站点
wp-cli
wp-cli is a super useful shell tool.
WP-CLI 是一个超级有用的 shell 工具。
wp search-replace 'example.dev' 'example.com' --skip-columns=guid
Or, if you only want to change the option, you can do:
或者,如果您只想更改选项,您可以执行以下作:
wp option update home 'https://example.com'
wp option update siteurl 'https://example.com'
Moving WordPress 移动 WordPress
Whether you are moving WordPress to a new server or to a different location on your server, you don’t need to reinstall. WordPress is flexible enough to handle all of these situations.
无论您是将 WordPress 移动到新服务器还是服务器上的其他位置,您都不需要重新安装。WordPress 足够灵活,可以处理所有这些情况。
Moving to a New Server 移动到新服务器
If you are moving WordPress from one server to another, begin by backing up your WordPress directory, images, plugins, and other files on your site as well as the database. See WordPress Backups and Backing Up Your Database.
如果您要将 WordPress 从一台服务器移动到另一台服务器,请先备份您的 WordPress 目录、图像、插件和您网站上的其他文件以及数据库。请参阅 WordPress 备份 和 备份数据库。
Keeping Your Domain Name and URLs 保留您的域名和 URL
Moving your domain without changing the Home and Site URLs of your WordPress site is very simple, and in most cases can be done by moving the files.
在不更改 WordPress 网站的主 URL 和站点 URL 的情况下移动域非常简单,在大多数情况下可以通过移动文件来完成。
- If database and URL remain the same, you can move by just copying your files and database.
如果 database 和 URL 保持不变,则只需复制文件和数据库即可移动。 - If database name or user changes, edit wp-config.php to have the correct values.
如果数据库名称或用户发生更改,请编辑wp-config.php以获得正确的值。 - If you want to test before you switch, you must temporarily change “siteurl” and “home” in the database table “wp_options” (through phpMyAdmin or similar).
如果你想在切换之前进行测试,你必须临时更改数据库表 “wp_options” 中的 “siteurl” 和 “home” (通过 phpMyAdmin 或类似)。 - If you had any kind of rewrites (permalinks) setup you must disable .htaccess and reconfigure permalinks when it goes live.
如果你有任何类型的重写(永久链接)设置,你必须禁用 .htaccess 并在它上线时重新配置永久链接。
Changing Your Domain Name and URLs 更改您的域名和 URL
Moving a website and changing your domain name or URLs (i.e. from https://example.com/site to https://example.com, or https://example.com to https://example.net) requires the following steps – in sequence.
移动网站并更改您的域名或 URL(即从 https://example.com/site 更改为 https://example.com,或从 https://example.com 更改为 https://example.net)需要按顺序执行以下步骤。
- Download your existing site files.
下载您现有的站点文件。 - Export your database – go in to MySQL and export the database.
导出您的数据库 – 进入 MySQL 并导出数据库。 - Move the backed up files and database into a new folder – somewhere safe – this is your site backup.
将备份的文件和数据库移动到新文件夹 – 安全的地方 – 这是您的站点备份。 - Log in to the site you want to move and go to Settings > General, then change the URLs. (ie from https://example.com/ to https://example.net) – save the settings and expect to see a 404 page.
登录到要移动的站点,然后转到设置 > 常规,然后更改 URL。(即从 https://example.com/ 到 https://example.net) – 保存设置并期望看到 404 页面。 - Download your site files again.
再次下载您的站点文件。 - Export the database again.
再次导出数据库。 - Edit
wp-config.php
with the new server’s MySQL database name, user and password.
使用新服务器的 MySQL 数据库名称、用户和密码编辑wp-config.php
。 - Upload the files. 上传文件。
- Import the database on the new server.
在新服务器上导入数据库。
When your domain name or URLs change there are additional concerns. The files and database can be moved, however references to the old domain name or location will remain in the database, and that can cause issues with links or theme display.
当您的域名或 URL 发生更改时,还有其他问题。文件和数据库可以移动,但对旧域名或位置的引用将保留在数据库中,这可能会导致链接或主题显示出现问题。
If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have three options:
如果对整个数据库进行搜索和替换以更改 URL,则可能会导致数据序列化问题,因为某些主题和小组件存储的值标记了 URL 的长度。当这种情况发生变化时,事情就会中断。要避免该序列化问题,您有三个选项:
- Use the Velvet Blues Update URLs or Better Search Replace plugins if you can access your Dashboard.
如果可以访问仪表板,请使用 Velvet Blues Update URL 或 Better Search Replace 插件。 - Use WP-CLI’s search-replace if your hosting provider (or you) have installed WP-CLI.
如果您的托管服务提供商(或您)已安装 WP-CLI,请使用 WP-CLI 的搜索替换。 - Use the Search and Replace for WordPress Databases Script to safely change all instances on your old domain or path to your new one. (only use this option if you are comfortable with database administration )
使用搜索和替换 WordPress 数据库脚本安全地将旧域或路径上的所有实例更改为新域。(仅当您熟悉数据库管理时,才使用此选项 )
Note: Only perform a search and replace on the wp_posts table.
注: 仅对 wp_posts 表执行搜索和替换。
Note: Search and Replace from Interconnectit is a 3rd party script
注意:从 Interconnectit 搜索和替换是第三方脚本
Moving Directories On Your Existing Server 在现有服务器上移动目录
Moving the WordPress files from one location on your server to another – i.e. changing its URL – requires some special care. If you want to move WordPress to its own folder, but have it run from the root of your domain, please read Giving WordPress Its Own Directory for detailed instructions.
将 WordPress 文件从服务器上的一个位置移动到另一个位置(即更改其 URL)需要特别小心。如果您想将 WordPress 移动到它自己的文件夹,但让它从您的域的根目录运行,请阅读 为 WordPress 提供自己的目录 以获取详细说明。
Here are the step-by-step instructions to move your WordPress site to a new location on the same server:
以下是将您的 WordPress 网站移动到同一服务器上的新位置的分步说明:
- Create the new location using one of these two options:
使用以下两个选项之一创建新位置:- If you will be moving your WordPress core files to a new directory, create the new directory.
如果您要将 WordPress 核心文件移动到新目录,请创建新目录。 - If you want to move WordPress to your root directory, make sure all
index.php
, .htaccess, and other files that might be copied over are backed up and/or moved, and that the root directory is ready for the new WordPress files.
如果您想将 WordPress 移动到您的根目录,请确保所有index.php
、.htaccess 和其他可能被复制的文件都已备份和/或移动,并且根目录已准备好用于新的 WordPress 文件。
- If you will be moving your WordPress core files to a new directory, create the new directory.
- Log in to your site.
登录到您的站点。 - Go to the Administration > Settings > General screen.
转到 Administration > Settings > General(常规)屏幕。 - In the box for WordPress Address (URL): change the address to the new location of your main WordPress core files.
在 WordPress 地址 (URL) 框中:将地址更改为主要 WordPress 核心文件的新位置。 - In the box for Site Address (URL): change the address to the new location, which should match the WordPress (your public site) address.
在站点地址 (URL) 框中:将地址更改为新位置,该位置应与 WordPress(您的公共站点)地址匹配。 - Click Save Changes.
单击 Save Changes。 - (Do not try to open/view your site now!)
(现在不要尝试打开/查看您的网站! - Move your WordPress core files to the new location. This includes the files found within the original directory, such as https://example.com/wordpress, and all the sub-directories, to the new location.
将您的 WordPress 核心文件移动到新位置。这包括在原始目录中找到的文件 (如 https://example.com/wordpress) 和所有子目录,这些子目录都保存到新位置。 - Now, try to open your site by going to yourdomain.com/wp-admin. Note, you may need to go to yourdomain.com/wp-login.php
现在,尝试通过转到 yourdomain.com/wp-admin 打开您的网站。请注意,您可能需要转到 yourdomain.com/wp-login.php - If you are using Permalinks, go to the Administration > Settings > Permalinks panel and update your Permalink structure to your .htaccess, file, which should be in the same directory as the main
index.php
file.
如果您使用的是永久链接,请转到 Administration > Settings > Permalinks 面板,并将您的永久链接结构更新为您的 .htaccess 文件,该文件应与主index.php
文件位于同一目录中。 - Existing image/media links uploaded media will refer to the old folder and must be updated with the new location. You can do this with the Better Search Replace or Velvet Blues Update URLs plugins, WP-CLI’s search-replace if your hosting provider (or you) have installed WP-CLI, manually in your SQL database, or by using the 3rd party database updating tool Search and Replace Databases Script * Note: this script is best used by experienced developers.
上传的现有图像/媒体链接将引用旧文件夹,并且必须使用新位置进行更新。您可以使用 Better Search Replace 或 Velvet Blues Update URLs 插件、WP-CLI 的搜索替换(如果您的托管服务提供商(或您)已安装 WP-CLI)、在您的 SQL 数据库中手动或使用第三方数据库更新工具搜索和替换数据库脚本来执行此作 * 注意:此脚本最适合有经验的开发人员使用。 - In some cases your permissions may have changed, depending on your ISP. Watch for any files with “0000” permissions and change them back to “0644”.
在某些情况下,您的权限可能已更改,具体取决于您的 ISP。监视具有 “0000” 权限的任何文件,并将其改回 “0644”。 - If your theme supports menus, links to your home page may still have the old subdirectory embedded in them. Go to Appearance > Menus and update them.
如果您的模板支持菜单,则指向主页的链接可能仍嵌入了旧的子目录。转到外观 > 菜单并更新它们。 - Sometimes you would need to restart your server, otherwise your server may give out an error. (happens in MAMP software (Mac)).
有时您需要重新启动服务器,否则您的服务器可能会发出错误。(发生在 MAMP 软件 (Mac) 中)。 - It is important that you set the URI locations BEFORE you move the files.
在移动文件之前设置 URI 位置非常重要。
If You Forget to Change the Locations
如果您忘记更改位置
If you accidentally moved the files before you changed the URIs: you have two options.
如果您在更改 URI 之前不小心移动了文件:您有两个选项。
- Suppose the files were originally in /path/to/old/ and you moved them to /path/to/new before changing the URIs. The way to fix this would be to make
假设文件最初位于 /path/to/old/ 中,并且在更改 URI 之前将它们移动到 /path/to/new。解决这个问题的方法是使
/path/to/old/ a symlink (for Windows users, "symlink" is equivalent to "shortcut") to /path/to/new/, i.e.
ln -s /path/to/new /path/to/old
and then follow the steps above as normal. Afterwards, delete the symlink if you want.
然后照常执行上述步骤。之后,如果需要,请删除符号链接。
- If you forget to change the WordPress Address and Blog Address, you will be unable to change it using the WordPress interface. However, you can fix it if you have access to the database. Go to the database of your site and find the wp_options table. This table stores all the options that you can set in the interface. The WordPress Address and Blog Address are stored as
siteurl
andhome
(the option_name field). All you have to do is change the option_value field to the correct URL for the records withoption_name='siteurl‘
oroption_name='home‘
.
如果您忘记更改 WordPress 地址和博客地址,您将无法使用 WordPress 界面进行更改。但是,如果您有权访问数据库,则可以修复它。转到您网站的数据库并找到 wp_options 表。此表存储了您可以在界面中设置的所有选项。WordPress 地址和博客地址存储为siteurl
和home
(option_name 字段)。您所要做的就是将 option_value 字段更改为option_name='siteurl'
或option_name='home'
记录的正确 URL。
Note: Sometimes, the WordPress Address and Blog Address are stored in WordPress Transients. Search and replace scripts can have trouble modifying those to the new address and some plugins might therefore refer to the old address because of them. Transients are temporary (cached) values stored in the wp_options database table that can be recreated on-demand when removed. It’s therefore safe to delete them from the migrated database copy and let them be recreated. This database query (again, have a backup!) clears all transients:
注意:有时,WordPress 地址和博客地址存储在 WordPress Transients 中。搜索和替换脚本在将它们修改为新地址时可能会遇到问题,因此某些插件可能会因此引用旧地址。瞬时是存储在 wp_options 数据库表中的临时(缓存)值,删除后可以按需重新创建。因此,可以安全地从迁移的数据库副本中删除它们,然后重新创建它们。这个数据库查询(同样,有一个备份!)清除了所有瞬态:
DELETE FROM `wp_options` WHERE option_name LIKE '%\_transient\_%'
If You Have Accidentally Changed your WordPress Site URL
如果您不小心更改了 WordPress 网站 URL
Suppose you accidentally changed the URIs where you cannot move the files (but can still access the login page, through a redirection or something).
假设您不小心更改了无法移动文件的 URI(但仍然可以通过重定向或其他方式访问登录页面)。
wp-login.php
can be used to (re-)set the URIs. Find this line:
wp-login.php
可用于(重新)设置 URI。找到此行:
require( dirname(__FILE__) . '/wp-load.php' );
and insert the following lines below:
并在下面插入以下几行:
//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', 'https://example.com/the/path' );
update_option('home', 'https://example.com/the/path' );
You’re done. Test your site to make sure that it works right. If the change involves a new address for your site, make sure you let people know the new address, and consider adding some redirection instructions in your .htaccess
file to guide visitors to the new location.
您已完成。测试您的网站以确保其正常运行。如果更改涉及您网站的新地址,请确保让人们知道新地址,并考虑在 .htaccess
文件中添加一些重定向说明以将访问者引导至新位置。
Changing The Site URL also provides the details of this process.
更改 站点 URL 还会提供此过程的详细信息。
Managing Your Old Site 管理您的旧站点
Shutting It Down 关闭它
- Download a copy of the main WordPress files from your OLD site to your hard drive and edit wp-config.php to suit the new server.
将主要 WordPress 文件的副本从您的旧站点下载到您的硬盘上,并编辑wp-config.php以适应新服务器。 - Go back to your OLD site and go to Administration > Settings > General screen and change the URL (both of them) to that of your new site.
返回您的旧站点,转到 Administration > Settings > General(常规)屏幕,然后将 URL(两者)更改为新站点的 URL。 - Login on your server, go to phpMyAdmin, export as file, and save your database (but keep the old one just in case). Now, upload this new database and the copy of the wordpress core files with the edited wp-config.php to your new server. That’s it!
登录您的服务器,转到 phpMyAdmin,导出为文件,并保存您的数据库(但保留旧数据库以防万一)。现在,将这个新数据库和 wordpress 核心文件的副本以及编辑后的wp-config.php上传到您的新服务器。就是这样!
Keeping it Running 保持运行
Caution: Make sure you have a backup of your old site’s WordPress database before proceeding!
警告: 在继续之前,请确保您有旧站点的 WordPress 数据库的备份!
Part A – Activating Your New Site
A 部分 – 激活您的新站点
- Download your entire WordPress installation to your hard drive. Name the folder appropriately to indicate that this is your OLD site’s installation.
将整个 WordPress 安装实例下载到硬盘上。为文件夹命名,以表明这是 OLD 站点的安装。 - Download your database. 下载您的数据库。
- Go back to your OLD site and go to options and change the url (both of them) to that of your new site.
返回您的旧站点并转到选项并将 url(两者都)更改为新站点的 url。 - Again, download your entire WordPress installation to your hard drive. Name the folder appropriately to indicate that this is your NEW site’s installation.
同样,将您的整个 WordPress 安装下载到您的硬盘上。适当地命名文件夹,以表明这是您的新站点的安装。 - Download your database once again (but keep the old one). Upload this database to your new server. It will be easiest if you use the same database name and you create a user with the same login credentials on your new server as on your old server.
再次下载您的数据库(但保留旧数据库)。将此数据库上传到您的新服务器。如果您在新服务器上使用相同的数据库名称并创建具有相同登录凭证的用户,这将是最简单的。 - If you used a different database name and/or user (see previous step), edit wp-config.php in your NEW site’s installation folder appropriately.
如果您使用了不同的数据库名称和/或用户(请参阅上一步),请在 NEW 站点的安装文件夹中适当地编辑 wp-config.php。 - Upload the NEW site’s installation folder to your new site. Presto, your NEW site should be working!
将 NEW 站点的安装文件夹上传到您的新站点。Presto,您的新网站应该可以正常工作了!
Part B – Restoring Your Old Site
B 部分 – 恢复您的旧站点
- On the original server, delete your OLD site’s database (remember, you should have a copy on your local computer that you made at the very beginning).
在原始服务器上,删除 OLD 站点的数据库(请记住,您应该在本地计算机上有一个一开始创建的副本)。 - Upload your OLD site’s installation folder to your original server, overwriting the files that are currently there (you may also delete the installation folder on the server and simply re-upload the OLD site’s files).
将 OLD 站点的安装文件夹上传到原始服务器,覆盖当前存在的文件(您也可以删除服务器上的安装文件夹,然后重新上传 OLD 站点的文件)。 - Upload your OLD site’s database from your local computer to the server. That should do it!
将 OLD 站点的数据库从本地计算机上传到服务器。那应该就可以了!
Another procedure for making copies of posts, comments, pages, categories and custom field (post status, data, permalinks, ping status, etc.) easy to follow:
制作帖子、评论、页面、类别和自定义字段(帖子状态、数据、永久链接、ping 状态等)副本的另一个过程很容易遵循:
- Install a new WordPress site
安装新的 WordPress 网站 - Go to the old site Admin panel. Here, in Manage > Export select “all” in the menu Restrict Author.
转到旧站点的 Admin 面板。在这里,在“管理 > 导出”中,选择菜单“限制作者”中的“全部”。 - Click on Download Export File
单击 Download Export File(下载导出文件) - In the new site go to Manage > Import, and choose WordPress item.
在新站点中,转到管理 > 导入,然后选择 WordPress 项目。 - On the page that will be shown, select the file just exported. Click on Upload file and Import
在将显示的页面上,选择刚刚导出的文件。点击上传文件并导入 - It will appear on a page. In Assign Authors, assign the author to users that already exist or create new ones.
它将出现在页面上。在 Assign Authors 中,将作者分配给已存在的用户或创建新用户。 - Click on Submit 点击 Submit
- At the end, click on Have fun
最后,单击 Enjoy fun
Note: using this method, if there are some articles in the new site (like Hello World, Info Page, etc.), these will not be erased. Articles are only added. Using the former procedure, the articles in the new site will be deleted.
注意:使用这种方法,如果新站中有一些文章(比如 Hello World、Info Page 等),这些文章不会被删除。仅添加文章。使用以前的过程,新站点中的文章将被删除。
Moving WordPress Multisite 移动 WordPress 多站点
Multisite is somewhat more complicated to move, as the database itself has multiple references to the server name as well as the folder locations. If you’re simply moving to a new server with the same domain name, you can copy the files and database over, exactly as you would a traditional install.
多站点的移动稍微复杂一些,因为数据库本身具有对服务器名称和文件夹位置的多个引用。如果您只是移动到具有相同域名的新服务器,则可以复制文件和数据库,就像传统安装一样。
If, instead, you are changing domains, then the best way to move Multisite is to move the files, edit the .htaccess
and wp-config.php
(if the folder name containing Multisite changed), and then manually edit the database. Search for all instances of your domain name, and change them as needed. This step cannot yet be easily automated. It’s safe to search/replace any of the wp_x_posts
tables, however do not attempt blanket search/replace without the Search and Replace for WordPress Databases script (aka the interconnectit script).
相反,如果您要更改域,则移动 Multisite 的最佳方法是移动文件,编辑 .htaccess
和 wp-config.php
(如果包含 Multisite 的文件夹名称已更改),然后手动编辑数据库。搜索您的域名的所有实例,并根据需要更改它们。这一步还不能轻易地实现自动化。搜索/替换任何 wp_x_posts
表都是安全的,但是不要在没有 Search and Replace for WordPress Databases 脚本(又名 interconnectit 脚本)的情况下尝试一揽子搜索/替换。
If you’re moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs
entries to change the folder name correctly. You should manually review both wp_site
and wp_blogs
regardless, to ensure all sites were changed correctly.
如果要将 Multisite 从一个文件夹移动到另一个文件夹,则需要确保编辑 wp_blogs
条目以正确更改文件夹名称。无论如何,您都应该手动检查 wp_site
和 wp_blogs
,以确保所有网站都已正确更改。
Also, manually review all the wp_x_options tables look for three fields, and edit them as needed:
此外,手动查看所有 wp_x_options 表,查找三个字段,并根据需要编辑它们:
- home 家
- siteurl siteurl 的
- fileupload_url
If you are moving from subdomains to subfolders, or vice-versa, remember to adjust the .htaccess file and the value for SUBDOMAIN_INSTALL in your wp-config.php
file accordingly.
如果您要从子域移动到子文件夹,反之亦然,请记住相应地调整 wp-config.php
文件中的 .htaccess 文件和 SUBDOMAIN_INSTALL 的值。
Related Links 相关链接
- Moving a blog from wordpress.com to self-hosted blog
将博客从 wordpress.com 移动到自托管博客 - Moving WordPress to a new domain or server
将 WordPress 移动到新的域或服务器 - Italian version of this article – Versione italiana dell’articolo
本文的意大利语版本 - Search and Replace for WordPress Databases
搜索和替换 WordPress 数据库 - PHP script to replace site url in WordPress database dump, even with WPML
PHP 脚本替换 WordPress 数据库转储中的站点 url,即使使用 WPML 也是如此 - The Duplicator plugin helps administrators move a site from one location to another
Duplicator 插件可帮助管理员将站点从一个位置移动到另一个位置 - Technical tutorial on moving your WordPress blog to Bitnami’s AWS configuration
有关将 WordPress 博客移动到 Bitnami 的 AWS 配置的技术教程
Migrating multiple blogs into WordPress multisite 将多个博客迁移到 WordPress 多站点
This tutorial explains how to migrate multiples WordPress installs to a WordPress multisite install. You can migrate sites that use their own domain names, as well as sites that use a subdomain on your primary domain.
本教程介绍如何将多个 WordPress 安装迁移到 WordPress 多站点安装。您可以迁移使用自己的域名的站点,也可以迁移使用主域上的子域的站点。
This tutorial assumes that you are hosting WordPress on a server using cPanel. If you are using another solution to manage your server, you’ll have to adapt these instructions.
本教程假设您使用 cPanel 在服务器上托管 WordPress。如果您使用其他解决方案来管理服务器,则必须调整这些说明。
Steps to Follow 要遵循的步骤
Backup your site 备份您的网站
Generate a full site backup in cPanel. It might also help to copy all the files on the server via FTP, so that you can easily access the files for plugins and themes, which you’ll need in a later step.
在 cPanel 中生成完整的站点备份。通过 FTP 复制服务器上的所有文件也可能有所帮助,这样您就可以轻松访问插件和主题的文件,您将在后续步骤中用到这些文件。
Export from your existing WordPress installs
从您现有的 WordPress 安装中导出
In each of your existing WordPress installations, go to Tools > Export in WordPress. Download the WXR files that contain all your posts and pages for each site. See the instructions on the Tools Export Screen.
在每个现有的 WordPress 安装实例中,转到 WordPress 中的工具 > 导出。下载包含每个站点的所有帖子和页面的 WXR 文件。请参阅 Tools Export 屏幕上的说明。
Make sure that your export file actually has all the posts and pages. You can verify this by looking at the last entry of the exported file using a text editor. The last entry should be the most recent post.
确保您的导出文件实际上包含所有文章和页面。您可以通过使用文本编辑器查看导出文件的最后一个条目来验证这一点。最后一个条目应该是最新的帖子。
Some plugins can conflict with the export process, generating an empty file, or a partially complete file. To be on the safe side, you should probably disable all plugins before doing the exports.
某些插件可能会与导出过程冲突,从而生成空文件或部分完成的文件。为了安全起见,您可能应该在进行导出之前禁用所有插件。
It’s also a good idea to first delete all quarantined spam comments as these will also be exported, making the file unnecessarily large.
首先删除所有隔离的垃圾评论也是一个好主意,因为这些评论也会被导出,从而使文件变得不必要地大。
Note: Widget configuration and blog/plugin settings are NOT exported in this method. If you are migrating within a single hosting account, make note of those settings at this stage, because when you delete the old domain, they will disappear.
注意:小部件配置和博客/插件设置不会在此方法中导出。如果要在单个主机账户中迁移,请在此阶段记下这些设置,因为当您删除旧域时,它们将消失。
Install WordPress 安装 WordPress
Install WordPress. Follow the instructions for Installing WordPress.
安装 WordPress。按照安装 WordPress 的说明进行作。
Activate multisite 激活多站点
Activate multi-site in your WordPress install. This involves editing wp-config.php
a couple of times. You need to use the subdomain, not the subdirectory, option. See the instructions on how to Create A Network.
在您的 WordPress 安装中激活多站点。这涉及到多次编辑wp-config.php
。您需要使用 subdomain,而不是 subdirectory 选项。请参阅有关如何创建网络的说明。
Create blogs for each site you want to import
为要导入的每个站点创建博客
Create blogs for each of the sites you want to host in separate domains. For example, importedblogdotorg.mydomain.com
.
为要在单独域中托管的每个站点创建博客。例如, importedblogdotorg.mydomain.com
.
Note: choose the name carefully, because changing it causes admin redirection issues. This is particularly important if you are migrating a site within the same hosting account.
注意:请仔细选择名称,因为更改名称会导致管理员重定向问题。如果您要迁移同一主机帐户中的站点,这一点尤其重要。
Import WXR files for each blog
为每个博客导入 WXR 文件
Go to the backend of each blog, and import the exported WXR file for each blog. Map the authors to the proper users, or create new ones. Be sure to check the box that will pull in photos and other attachments. See the instructions on Tools Import SubPanel.
转到每个博客的后端,并为每个博客导入导出的 WXR 文件。将作者映射到适当的用户,或创建新用户。请务必选中将提取照片和其他附件的框。请参阅工具导入 SubPanel 上的说明。
Note: If you choose to import images from the source site into the target site, make sure they have been uploaded into the right place and are displayed correctly in the respective post or page.
注意:如果您选择将图像从源站点导入到目标站点,请确保它们已上传到正确的位置,并正确显示在相应的文章或页面中。
Edit WordPress configuration settings for each site
编辑每个站点的 WordPress 配置设置
Edit the configuration settings, widget, etc. for each site. By the end of this step, each site should look exactly as it did before, only with the URL subdomain.example.com
or example.com/subsite
rather than its correct, final URL.
编辑每个站点的配置设置、小组件等。在此步骤结束时,每个网站的外观都应该与以前完全相同,只是网址 subdomain.example.com
或 example.com/subsite
,而不是正确的最终到达网址。
Limitations of PHP configuration
PHP 配置的限制
You may run into trouble with the PHP configuration on your host. There are two potential problems. One is that PHP’s max_upload_size
will be too small for the WXR file. The other problem is that the PHP memory limit might be too small for importing all the posts.
您可能会遇到主机上的 PHP 配置问题。有两个潜在的问题。一个是 PHP 的 max_upload_size
对于 WXR 文件来说太小了。另一个问题是 PHP 内存限制可能太小,无法导入所有文章。
There are a couple of ways to solve it. One is to ask your hosting provider to up the limits, even temporarily. The other is to put a php.ini file in your /wp-admin/ and /wp-includes directories that ups the limits for you (php.ini files are not recursive, so it has to be in those directories). Something like a 10 MB upload limit and a 128 MB memory limit should work, but check with your hosting provider first so that you don’t violate the terms of your agreement.
有几种方法可以解决这个问题。一种是要求您的托管服务提供商提高限制,即使是暂时的。另一种是将 php.ini 文件放在 /wp-admin/ 和 /wp-includes 目录中,这会增加您的限制(php.ini文件不是递归的,因此它必须位于这些目录中)。10 MB 上传限制和 128 MB 内存限制应该有效,但请先咨询您的托管服务提供商,以免违反协议条款。
Search the WordPress forum support for help with PHP configuration problems.
搜索 WordPress 论坛支持以获取有关 PHP 配置问题的帮助。
Converting add-on domains to parked domains
将附加组件域转换为托管域
Deleting add-on domains in cPanel and replacing them with parked domains will also delete any domain forwarders and e-mail forwarders associated with those domains. Be aware of this, so that you can restore those forwarders once you’ve made the switch.
删除 cPanel 中的附加域并将其替换为停放域也将删除与这些域关联的任何域转发器和电子邮件转发器。请注意这一点,以便您可以在进行切换后恢复这些转发器。
Limitations of importing users
导入用户的限制
As there is the above way to import the content into an instance of the Multisite-blog, you are running into massive troubles, when it gets to import multiple users. Users are generated during the import, but you won’t get any roles or additional information into the new blog.
由于有上述方法可以将内容导入 Multisite-blog 的实例,因此当它导入多个用户时,您会遇到巨大的麻烦。在导入过程中会生成用户,但您不会将任何角色或其他信息引入新博客。
Losing settings 丢失设置
If the old site is no longer available and you find you have forgotten to copy some setting or you want to make sure you have configured everything correctly, run a google search for your site and then click to view the cached version. This option is available only until your new site has been crawled, so you’d better be quick.
如果旧站点不再可用并且您发现忘记复制某些设置,或者您想确保已正确配置所有内容,请为您的网站运行 google 搜索,然后单击以查看缓存版本。此选项仅在您的新网站被抓取之前可用,因此您最好快点。
Another option might be the Internet Archive Wayback Machine. They may have a copy of the site (or some part of it) archived.
另一个选项可能是 Internet Archive Wayback Machine。他们可能已存档该网站(或其中的一部分)的副本。
Please indicate: 无趣的人生也产生有意思的事件 » wordpress变更Domain域名