WordPress:Changing The Site URL

来自站长百科
Fludlen讨论 | 贡献2008年6月21日 (六) 15:39的版本
跳转至: 导航、​ 搜索


WordPress stores two addresses inside the database. These determine where your blog files are, and where the main index is. On a normal install, these addresses are the same.

WordPress在数据库中储存了两个地址。这两个地址决定了你的博客文件的位置和主索引的位置。在一次普通安装中,这些地址都是相同的。

There are two occasions where you will need to access the database to alter one or both of these settings:

在两种情况下,你需要访问数据库来更改一个或者这两个设置。

  1. If you have tried to alter the Blog URL or WordPress URL in Options and an error has occurred.
  2. 如果你试图在选项中更改博客URL或者WordPress URL,会出现一个错误。
  1. If you have moved to a domain/subdomain with a different name.
  1. 如果你使用了一个不同的名称,移到了一个域/子域。

BACKUP your database before you begin and store the backup off your site server, like on your hard drive. See: WordPress:Backing Up Your Database.

在你开始和储存备份的之前,将你的数据库在你的站点服务器上备份,例如在你的硬盘上。请看看: 备份你的数据库

Changing the URL

更改 URL

  1. Backup your database and save the copy off-site.
  1. 备份你的数据库 并且保存 copy off-site。
  1. Login to WordPress:phpMyAdmin.
  2. 登录到phpMyAdmin
  1. Click the link to your Databases.
  2. 点击链接,连接到你的数据库
  1. A list of your databases will appear. Choose the one that is your WordPress database.
  1. 你的数据库的一个列表会显示。选择一个你的WordPress的数据库。
  1. All the tables in your database will appear on the screen.
  1. 你的数据库中所有的表格都会出现在界面上。
  1. From the list, look for wp_options. Note: The table prefix of wp_ may be different if you changed it when installing.
  1. 从列表中,查找wp_选项注:如果你在安装的时候更改了,wp_的表格前缀可能会有所不同。
  1. Click on the small icon indicated as Browse.
  2. 点击显示为浏览的小图标。
  1. A screen will open with a list of the fields within the wp_options table.
  1. 一个界面会打开,上面有wp_选项表格中的一些栏。
  1. Under the field option_name, scroll down and look for siteurl.
  1. 选项_名栏的下面,下滚并且查找siteurl
  1. Click the Edit Field icon which usually is found at the far left at the beginning of the row.
  1. 点击编辑 栏图标,这个图标通常位于首行的最左边。
  1. The Edit Field window will appear.
  1. 编辑 栏窗口就会出现。
  1. In the input box for option_value, carefully change the URL information to the new address.
  1. 选项_值输入框中,认真地将URL信息改为新的地址。
  1. Verify this is correct and click Go to save the information.
  2. 确认这是正确的并且点击Go(运行)来保存信息。
  1. You should be returned to your wp-options table.
  2. 你应该被返回到你的wp-选项表格。
  1. 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.
  1. 查找表格中的home区,并且点击编辑field :在wp_选项中有几个网页的表格。在这些网页中,查找>符号。
  1. In the input box for option_value, carefully change the URL information to the new address.
  1. 选项_值的输入框中,认真地将URL信息改为新的地址。
  1. Verify this is correct and click Go to save the information.
  1. 核查这是正确的,并且点击Go(运行)来保存信息。
  1. Delete the folder wp-content/cache (this is a new folder added with WordPress 2.0).
  1. 删除文件夹wp-内容/高速缓存(这是添加到WordPress2.0上新的文件夹)。
  1. That is it.
  1. 就这么多了。

Domain Name Change

更改域名

BE VERY CAREFUL WITH THIS.

请认真对待。


IT WILL HURT.

会有不好的影响。

BACKUP YOUR DATABASE FIRST: WordPress:Backing Up Your Database.

首先备份你的数据库:备份你的数据库

The following is irreversible. There is no "undo" or "undelete" button. This is permanent. Be warned that it can do harm.

下面的执行是不能够取消的。没有"取消"或者 "恢复被删除文件"按钮。这个执行是永久性的。要注意这个步骤不会引起不好的后果。

When moving the domain, you will need to restore the database. You then need to upload your files to their new location.

当移动域的时候,你需要重建数据库。然后你需要将你的文件上传到新的位置上。

At this point, your blog will NOT work.

这时,你的博客不能够运行。

  1. Database
  2. 数据库
    1. Follow the guide above to alter the information in the database.
    2. 遵循上述的指南来更改数据库中的信息。
  1. Database Entries
  1. 数据库内容
    1. Log into WordPress:phpMyAdmin.
    1. 登录到phpMyAdmin
    1. Backup your database and save the copy off-site.
    1. 备份你的数据库并且保存copy off-site。
    1. Login to WordPress:phpMyAdmin.
    1. 登录到phpMyAdmin
    1. Click the link to your Databases.
    2. 点击,链接到你的数据库
    1. A list of your databases will appear. Choose the one that is your WordPress database.
    1. 会显示一列你的数据库。选择一个你的WordPress的数据库。
    1. Look for the name of the table within your database used to hold your post information. Usually it is called wp_posts, but it may have been changed. Write it down.
    1. 查找数据库中用来放置你的文章信息的表格的名称。通常名称是wp_文章,但是有可能这个名称已经更改了。将这个名称写下来。
    1. Clicking the Browse icon or link, open the wp_posts table.
    1. 点击浏览图标或者链接,打开wp_文章表格。
    1. Look for the field that holds your post "guid". It is usually called guid, but it may have been changed. Write it down.
    1. 查找包含你的文章"guid"的区域。这个区通常称为guid,但是这个名称可能已经更改了。将这个名称写下来。
    1. Click the tab at the top for SQL.
    2. 点击顶上方的标签来SQL
    1. Using the information you wrote down from above and the old and new URL addresses you wish to update or search and replace within your database, type in the following (CAREFULY):
    1. 使用你在上述步骤中写下的信息和你想要更新或者搜索的旧的和新的URL地址,在你的数据库中替换地址,输入以下的内容(认真地):
UPDATE wp_posts SET guid = REPLACE (
guid,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');


UPDATE wp_posts SET guid = REPLACE (
guid,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');


    1. Make sure that the names of wp-posts and post_content match the tables and fields within your database. Change them if not.
    1. 要确保wp-postspost_content名称与你的数据库内的表格和表格栏向匹配。如果不匹配的话,就要更改这些名称。
    1. Ensure that the ONLY content you want to change are within the little single 'quotes' . Make sure EVERYTHING is spelled right and that you are sure this is correct.
    1. 要确保你想要更改的内容在小的单 '引号' 之内。要确保所有的内容都是正确拼写的而且你确定这些拼写是正确的。
    1. Review everything within the SQL input box again. Make sure it is correct. There are no second changes when you take the next action. The change is permanent.
    1. 在一次地在SQL输入框中阅读所有的内容。要确保这些内容是正确的。当你执行下一个步骤的时候,就没有再次更改的机会了。下一步中的更改是永久性的。
    1. When you are sure, click Go.
    1. 当你确定的时候,点击Go(运行)。
    1. At the top of the screen will be generated a list of how many of the tables and fields have been changed.
    1. 在界面的上方,会产生一个列表,显示了更改了多少个表格和表格栏。

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主题中,打开每个模板文件并且搜索任何动手给你的老域输入references,并且将这个替换为新的。查找特别的手工编码的链接,你可能将这些链接输入到不同的模板文件中,例如sidebar.phpfooter.php

WordPress uses a template tag called bloginfo() to automatically generate your site address from information entered in your Options panel. The tag in your template files will not have to be modified.

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配置文件。

  1. You will only need to modify the config file if:
  2. 你值需要更改配置文件,如果:
    1. your database has moved to another server and is not running on your localhost
    2. 你的数据库移到另一个服务器而且不在本地主机上运行。
    1. you have renamed your database
    2. 你需要重新命名你的数据库
    1. you have changed the database user name
    1. 你更改了数据库用户名
  1. "'Make a backup copy of your wp-config.php file.'"
  2. "'制作一个 wp-config.php 文件的备份拷贝。'"
  1. Open the wp-config.php file in a text editor.
  1. 打开文本编辑器中的wp-config.php文件。
  1. Review its contents. In particular, you are looking for the database host entry.
  1. 阅读文件内容。你要特别查找数据库主机内容
  1. Save the file.
  2. 保存文件。

At this point, your WordPress blog should be working. 这时,WordPress博客应该可以运行。

Verify the Profile

核实个人基本资料

  1. In your WordPress:Administration Panels go to Options > General. Here you will verify that the changes you made in Changing the URL above, are correct.
  1. 管理面板中,进入选项 > 总的。这儿会确认你在上面的更改 URL上所作的更改是正确的。
  1. Verify that the reference in your WordPress URI contains the new address.
  2. 确认你的WordPress URI中包含的参考包含了新的地址。
  1. Verify that the reference in your "Blog URI" contains the new address.
  2. 确认你的"博客 URI"中的参考包含了新的地址。
  1. If you have made changes, click Update Options.
  1. 如果你更改了,点击更新选项

Changing the .htaccess file

更改 .htaccess 文件

After changing the information in your Options > General panel, you will need to update your .htaccess file if you are using Permalinks or any rewrites or redirects.

选项 > 面板上更改了信息之后,如果你正使用Permalinks或者其它的rewrites或者redirects的话,你需要更新你的.htaccess文件。

  1. Make a backup copy of your .htaccess file. This is not a recommendation but a requirement.
  1. 做一个 .htaccess 文件的备份。这并不是一个建议而是一个要求。
  1. Open the .htaccess file in a text editor.
  1. 在一个文字编辑器中打开.htaccess文件。
  1. Review its contents, looking for any custom rewrites or redirects you entered. Copy these to another text file for safe keeping.
  1. 阅读这个文件的内容,并且查找你输入的任何自定义rewrites或者redirects。将这些内容拷贝到另一个文字编辑器中以便安全地保存。
  1. Close the file.
  2. 关闭文件。
  1. Follow the instructions on the Permalinks SubPanel for updating your Permalinks to the .htaccess file.
  2. 遵循Permalinks子面板上的指示说明,将你的Permalinks更新到.htaccess文件。
  1. 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.
  2. 打开新的.htaccess文件并且查看你的rewrites和redirects是否还在那儿。如果不在,从保存的文件中复制rewrites和redirects,并且将其粘贴进新的.htaccess文件。
  1. Make any changes necessary in those custom rewrites and redirects to reflect the new site address.
  1. 在那些自定义的rewrites和redirects中做一些必要的更改,反映新的站点地址。
  2. Save the file.
  3. 保存文件。
  4. Test those redirects to ensure they are working.
  5. 测试这些redirects,确保这些redirects正在运行。

If you make a mistake, you can WordPress:Restoring Your Database From Backup from your backup and try this again. So make sure it is right the first time.

如果你犯了一个错误,你可以从你的文件备份中从文件备份中重建数据库并且在做一次重建。确保第一次就是对的。

Additional Information

额外信息

Much of this information was taken from Podz' WordPress Guides where this topic is also discussed.

大多数信息是来自Podz的WordPress 指导 ,这个话题在这里也得到了讨论。

See also: How to move a WordPress blog to a new URL or domain

也看看:怎样将 WordPress博客移到一个新的 URL或者域