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
WordPress数据库存储了两个地址,它们分别决定着博客文件和主要索引的位置。在正常情况下,这两个地址是相同的。
遇到以下两种情况时,你需要访问数据库以更改地址:
方法2:
快速修复
如果你通过FTP访问网站,这个方法能让你快速备份网站,并使其正常运行。
1. 通过FTP访问网站,复制当前主题的functions.php文件。然后,使用纯文本编辑器(如记事本)编辑这个文件并把它回传到网站。
2. 在开头”<?php”后插入以下两行内容:
当然要使用你自己的URL而非以上的example.com。
3. 把文件回传到网站的相应位置。通过FileZilla敏捷的“文件编辑”功能可以快速完成以上操作。
4. 多次载入登陆或管理页面。网站很快就会正常运行。
5. 重复以上操作,但删除刚才插入的文字。注意:不要保留插入的文字。网站运行后要立即删除它们。
如果主题中没有functions.php文件,请创建一个名为”functions.php”的文本文件。并使用记事本编辑这个文件,然后把以下文字插入进去(使用自己的URL,而非以下的example.com):
把编辑后的新文件上传到主题目录,然后按以上所述操作。网站正常运行后,删除文件。
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可以直接在数据库中修改属性值以使网站正常运行。
更改域名
慎重操作!首先备份数据库。以下操作不可撤消,操作永久有效,请确保操作不会对你造成损失。
移动域名时,需要恢复数据库。然后需要把文件上传到新地址。
此过程中,博客不运行。
UPDATE wp_posts SET guid = REPLACE ( guid, 'http://exampleoldsiteurl.com', 'http://examplenewsiteurl.com');
(注意,有次我按上面更改后,首页的链接还是原来的链接。点击log in 显示找不到文件。可以直接输地址进入后台,在通用设置那里更改wordpress url 和siteurl 就可以了,这比用relocate或更改数据库的option_value更好,推荐用这种办法,直接进入后台那里.)
更改模板文件
在WordPress主题中,打开模板文件,搜索所有手动输入的旧域名并把它更换为新域名。同时搜索在各个模板文件(如sidebar.php和 footer.php)可能手动输入的编码链接。
更改配置文件
如果数据库已被移动或更改,就需要更新配置文件了。
这时,你的博客可以正常运行了。
核实资料
更改.htaccess文件
在管理>设置 > 常规面板更改信息后,如果你使用了永久链接或其它改写、重定向结构,你还需要更新.htaccess文件。
如果操作失误,可以从备份中恢复数据库,然后再按以上方法重新操作。但尽量要保证操作无误。
还可以看:
原文链接:https://www.cnblogs.com/youxin/archive/2012/07/21/2602603.html