wordpress 更改网站 URL

  方法1:Here are the initial steps you’ll want to take when moving to a new domain name.

Existing Domain:

Export Your WordPress Posts – 导出文章 You can find the Export option under the Manage tab in your WordPress dashboard.  You’ll want to save the file somewhere on your hard drive where you can find it a little later. 

Download Your wp-content Folder – 下载wp_content文件夹。This step requires FTP access.  You’ll want to copy over your wp-content folder on to your hard drive or place it somewhere you can find it later so that you can upload it to your new domain.  This should grab all of your existing plugins, themes, uploads (pictures), etc.   You’ll also want to download your favicon and Robots.txt file (if you have either).

Sub Domains and Sub Directories – This won’t apply to everyone, but if you’ve set up any sub domains or sub directories for your blog, you’ll want to grab the same files from them as well.

 

New Domain:

  • Install WordPress on the New Domain – This can be done manually or via Fantastico if you have CPanel.
  • Upload Your wp-content Folder – 把下载的wp-content重载进去。This requires FTP access to complete.  Just override the existing wp-content folder from your fresh WordPress install.
  • Import All WordPress Posts – 导入文章。You can find the Import option under the Manage tab in your WordPress dashboard.  When it asks for the import file, use the one that was exported and saved on your hard drive earlier.
  • Activate Your Theme & Plugins – Head into the Design and Plugins tabs and make sure you have the same theme and same plugins activated as the old domain name.
  • Update Your Settings to Match the Old Domain – Update all of your settings to match the old domain, including all of your plugin settings you just activated.
  • Inspect Your Theme – View your theme with your plugins activated and settings in place to ensure that everything looks like it matches the old site on the new domain.  Test some of the functionality as well to ensure everything is working properly.
  • Upload and Run the Update URL’s Plugin – The Update URL’s WordPress pluginis brand new (just came out this month) WordPress plugin and the timing couldn’t have been more perfect for me!  Once activated, simply enter your old domain URL and the new one.  It will go through all of your old posts and update the domain part of the URL with the new one, and it only takes a matter of seconds.  Note:  I won’t update anchor text, only the domain in the URL.
  • Repeat Steps for Sub Domains and Sub Directories – Upload and setup your sub domains and sub directories using the same steps above

via:http://wphacks.com/how-to-move-wordpress-blog-new-domain-name/

WordPress数据库存储了两个地址,它们分别决定着博客文件和主要索引的位置。在正常情况下,这两个地址是相同的。

遇到以下两种情况时,你需要访问数据库以更改地址:

  1. 在设置中更改博客URL或WordPress URL后,出现了错误。
  2. 把博客移到了其它域名或子域名下。

    在开始之前,请备份数据库,并把其存储在硬盘驱动上。 

方法2:

快速修复

如果你通过FTP访问网站,这个方法能让你快速备份网站,并使其正常运行。

1. 通过FTP访问网站,复制当前主题的functions.php文件。然后,使用纯文本编辑器(如记事本)编辑这个文件并把它回传到网站。

2. 在开头"<?php"后插入以下两行内容:

update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');

当然要使用你自己的URL而非以上的example.com。

3. 把文件回传到网站的相应位置。通过FileZilla敏捷的“文件编辑”功能可以快速完成以上操作。

4. 多次载入登陆或管理页面。网站很快就会正常运行。

5. 重复以上操作,但删除刚才插入的文字。注意:不要保留插入的文字。网站运行后要立即删除它们。

如果主题中没有functions.php文件,请创建一个名为"functions.php"的文本文件。并使用记事本编辑这个文件,然后把以下文字插入进去(使用自己的URL,而非以下的example.com):

<?php
update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');

把编辑后的新文件上传到主题目录,然后按以上所述操作。网站正常运行后,删除文件。

重置

WordPress在网站URL更改后能自动更新属性值。这使网站在移到另一个服务器后能快速开始正常运行。

步骤: 

1. 编辑wp-config.php文件。

2. 在"define"语句后,插入 define('RELOCATE',true);

3.打开wp-login.php页面。

4. 正常登陆。

RELOCATE值设置为TRUE时,siteurl(非首页设置)会自动更新为登陆页面的url。这将使管理页面在新URL上正常运行,但其它页面的设置则需要手动更改。(如wordpress url已经自动改好了,但是siteurl addres还要自己更改

 网站正常运行后,要删除刚才插入的文字。

在数据库中直接更改URL

访问主机上的phpMyAdmin可以直接在数据库中修改属性值以使网站正常运行。

  1. 备份数据库并把其保存在硬盘驱动上。
  2. 登陆phpMyAdmin
  3. 点击数据库链接。
  4. 在系统弹出的数据库列表页面上选择你的WordPress数据库。
  5. WordPress数据库的所有表格将出现在屏幕上。
  6. 查找wp_options。注意:如果安装时你作了修改,可能表格的前缀并不是wp_
  7. 点击Browse(浏览)图标。
  8. 系统将显示wp_options表格中的所有域。
  9. option_name下,查找siteurl
  10. 点击此行左侧的Edit Field图标。
  11. 系统将弹出Edit Field窗口。
  12. option_value的输入框中,把URL改为新地址。(其实这个跟define('RELOCATE',true是一样的,都是更改siteurl
  13. 确认信息输入正确后,点击 Go以保存信息。
  14. 系统返回wp-options表格。
  15. 查找表格中的home域,点击Edit Field。注意wp_options表格有多个页面。使用页面的> 符号以浏览页面。
  16. option_value的输入框中,把URL改为新地址。
  17. 确认信息输入正确后,点击 Go以保存信息。
  18. 删除文件夹wp-content/cache(WordPress 2.0新添加的文件夹)
  19. 大功告成啦!

更改域名

慎重操作!首先备份数据库。以下操作不可撤消,操作永久有效,请确保操作不会对你造成损失。

移动域名时,需要恢复数据库。然后需要把文件上传到新地址。

此过程中,博客不运行。

  1. 数据库
    1. 根据以上步骤更改数据库信息。
  2. 数据库内容
    1. 登陆phpMyAdmin。
    2. 备份数据库并把它存储在硬盘驱动。
    3. 登陆phpMyAdmin。
    4. 点击数据库链接。
    5. 在系统弹出的数据库列表页面上选择你的WordPress数据库。
    6. 查找数据库中包含日志信息的表格名称,通常是wp_posts,但也可能不是,写下表格名。
    7. 点击Browse 图标或链接,打开wp_posts表格。
    8. 查找包含日志"guid"的域,通常是guid,但也可能不是,写下这个域的名称 。
    9. 单击顶端标签SQL。
    10. 使用刚才记下的信息和需要更改的新旧URL地址,并在数据库中通过查找和替换进行更新,输入以下内容(谨慎行事!)
UPDATE wp_posts SET guid = REPLACE (
guid,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');
    1. 确保wp-posts 和post_content与数据库中的表格和域相对应。如果不对应,要作相应改变。
    2. 确保你要更改的唯一内容在单引号‘’中。确保所有拼写正确。
    3. 再次审核SQL输入框中的内容以确保输入正确。此操作不可撤销!
    4. 点击Go。
    5. 屏幕上端会显示已更改表格和域的数量。

  (注意,有次我按上面更改后,首页的链接还是原来的链接。点击log in 显示找不到文件。可以直接输地址进入后台,在通用设置那里更改wordpress url 和siteurl 就可以了,这比用relocate或更改数据库的option_value更好,推荐用这种办法,直接进入后台那里.)

更改模板文件

在WordPress主题中,打开模板文件,搜索所有手动输入的旧域名并把它更换为新域名。同时搜索在各个模板文件(如sidebar.php footer.php)可能手动输入的编码链接。

WordPress 使用名为bloginfo()的模板标签,会根据管理>设置 > 常规面板的信息自动生成网址,因此,无需更改模板文件的标签。

更改配置文件

如果数据库已被移动或更改,就需要更新配置文件了。

  1. 发生以下情况时,需要更改配置文件:
    1. 数据库已移到其它服务器上,不在localhost运行了
    2. 数据库已重命名
    3. 数据库用户名已更改
  2. 备份wp-config.php 文件
  3. 在文本编辑器中打开wp-config.php文件
  4. 审查内容,主要检查数据库条目
  5. 保存文件。

这时,你的博客可以正常运行了。

核实资料

  1. 在管理面板,进入设置 > 常规面板。在此,你可核实以上所更改的URL是否正确。
  2. 核实WordPress URL中的新地址。
  3. 核实"博客URL"中的新地址。
  4. 点击保存更改

更改.htaccess文件

在管理>设置 > 常规面板更改信息后,如果你使用了永久链接或其它改写、重定向结构,你还需要更新.htaccess文件。

  1. 务必备份.htaccess文件。
  2. 在文本编辑器中打开.htaccess文件。
  3. 浏览文件内容并查找以前输入的所有自定义改写或重定向结构。然后,把这些内容复制到其它文本文件以作保存。
  4. 关闭文件。
  5. 按照永久链接子面板上的更新永久链接到.htaccess文件的说明进行操作。
  6. 打开新的.htaccess文件以查看自定义改写或重定向结构是否存在。如果不存在,从已保存的文件中复制过来然后把其粘贴到新的.htaccess文件中。
  7. 为符合网站新地址,请给自定义改写和重定向结构作相应更改。
  8. 保存文件。
  9. 测试重定向网址是否有效。

如果操作失误,可以从备份中恢复数据库,然后再按以上方法重新操作。但尽量要保证操作无误。

 via :http://www.wordpress.la/codex-%E6%9B%B4%E6%94%B9%E7%BD%91%E7%AB%99URL.html

还可以看:

http://biven.org/2008/01/31/migrating-wordpress-to-a-different-domain-or-server/

 

原文地址:https://www.cnblogs.com/youxin/p/2602603.html