wordpress实现附件分离到另一服务器

由于我的Blog从2004年就开始写了,当时最早的第一版是自已整的程序,到现在那些数据基本也丢掉录。后来大约在2005年时采用了eblog(应该这么称)才算真正用起了BLOG。经过这么多年的折腾,BLOG程序换了很多回。有PLBLOG,lxblog(不知有没有记对名称)至现在用的Wordpress。显然也产生了很庞大的附件(300M左右吧),主要还是是自已的摄影图片为主了。这个绝对不能丢失了。一直想把附件移至另一服务器空间上,找了很久也没有发现什么好的方法可以解决。
最后找到以下方法,先记录下来,以备使用:
此方法来来源于:http://www.at-blog.com/2010/03/wp-attachment-url.html

/**
* Enter description here…
*
* @todo 新的域名可以通过配置页面进行配置
*
* @param unknown_type $content
* @return unknown
*/

function setting_another_domain_for_media($content) {
$content = str_replace( get_bloginfo('home').'/wp-content/','http://my.crazyenglish.info/',$content);
return $content;
}

add_filter( 'the_content','setting_another_domain_for_media',12 )

?>

当然,还可以在apache或者ngnix中通过mod_rewrite进行地址重写,重写规则如下:

server
{
listen 80;
server_name my.crazyenglish.info;
index index.html index.php index.htm;
root /www/my.crazyenglish.info/wp-content/;
}

相关文章

2010-04-02 at 20:21 posted in:Code Comments (2) 标签:, , ,

2 条评论»

  1. wuzhl 说:

    麻烦请教一下第一段代码是修改的哪一个文件?
    如果能提供详细的设置方法就好了。

发表评论

(必填)

(必填)您的电子邮箱不会被公开。

=2+5(必填)请输入两数的和。

有新的评论时通过 email 通知我

人物志 - 雨过天晴是我最想念你的时候,想你陪着我吹着风,看着海。