本文介绍WordPress从新浪云SAE迁移到亚马逊云AWS后,如何批量修改图片的URL。

1. 从SAE下载uploads文件夹

新浪云SAE因不支持在代码目录进行IO操作,所以用Storage存储/wp-content/uploads/。所以第一步是将Storageuploads整个文件夹下载下来,再上传到AWS下的/var/www/wordpress/wp-content/uploads/。用CyberDuck工具下载,官方教程在这里

2. 批量修改URL

将uploads弄好,还没玩。之前uploads用Storage存储,网站上所有图片的URL形如:http://zhilitea-wordpress.stor.sinaapp.com/uploads/2015/04/jinhua_wechat_qrcode.jpg

而正常的图片URL形如:http://zhilitea.com/wp-content/uploads/2015/04/jinhua_wechat_qrcode.jpg

那么问题就简单了,只要在数据库的wp_posts表,批量修改URL的前缀即可。

进入phpmyadmin后台管理(如:http://zhilitea.com/phpmyadmin/),点击相应的数据库(如zhilitea),点击SQL,在文本框中输入以下语句,点GO。

UPDATE wp_posts SET post_content = replace(post_content, 'http://zhilitea-wordpress.stor.sinaapp.com/uploads/', 'http://zhilitea.com/wp-content/uploads/');

搞定,现在的图片地址形如: http://zhilitea.com/wp-content/uploads/2015/04/jinhua_wechat_qrcode.jpg

掌握了这个,以后网站换域名,也不是难事了。

参考资料:

[1] Blog: BULK CHANGE URL PATHS USING SQL

[2] Blog: Batch changing URL of post images in wordpress

本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-04-17 11:24

results matching ""

    No results matching ""