02

godaddy免费空间wordpress后台错误的解决:(1)feed错误的解决方案

在浏览器里打开feed地址,不能像正常的feed订阅那样出来订阅的页面,在firefox下是直接以纯文本形式显示,IE7下显示“已取消到该 网页的导航”,而直接通过google reader等倒是能正常订阅。在Feed Validator上检查feed文件的正确性,问题如下:

This feed does not validate.
line 1, column 1: Blank line before XML declaration [help]
line 42, column 1: XML parsing error: :42:1: not well-formed (invalid token) [help]

虽然对于我这blog来说feed订阅这东西短期内基本上是拿来摆设的,不过有这问题心里总是不爽,于是乎网上搜寻解决办法,皇天不负有心人,最后 顺利解决问题了,下面就介绍一下我的解决方法(方法非原创,参考了SAM LESHER)。

先说说引起这个问题的原因:godaddy免费空间CreatingDrew), 因为godaddy会 自动加上一段广告代码,所以在feed的XML文件输出时也在文件的最后两行给加上了广告代码,并在最前面加了一个空行,这就是上面检查出的问题,所以只 要去了这个空行和广告代码就OK了,步骤大致如下:

1. 根据wordpress输出feed的默认地址下载feed文件到本地,这个文件是包含广告代码的
2. 写脚本,使用sed对文件进行过滤,把开头的空行和广告给删除掉
3. 通过修改后的feed文件输出feed订阅信息
4. 在godaddy管 理页面上建一条cron任务,每隔一定时间执行一遍脚本,使更新后的feed地址也是正常的

可以把feed文件下载和过滤都写到一个脚本里,修改feed地址则可以使用插件来完成。

下面是实现脚本:

#!/bin/sh
BLOGADDRESS="http://blog.happysa.org" #blog地址,用于下载feed文件
FEEDPATH=/var/www/home/happysa/domains/happysa.org/public_html/feed #下载后的feed文件存放地址,路径根据具体情况修改
FEEDFILE=$FEEDPATH/feed.xml
RSSFILE=$FEEDPATH/rss.xml
RDFFILE=$FEEDPATH/rdf.xml
ATOMFILE=$FEEDPATH/atom.xml
COMMENTSFILE=$FEEDPATH/comments.xml
#GDSTRING1="</object></layer></span></div></table></body></html><!-- adsok -->"
#GDSTRING2="<script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script>"
�
if [ -f $FEEDFILE ]; #删除老的feed文件
then
    rm -f $FEEDFILE
fi
wget -q $BLOGADDRESS/feed -O $FEEDFILE #下载feed文件
sed -i '/!-- adsok --/d;/alphagodaddy/d;1d' $FEEDFILE #过滤广告代码和最前面的空行,过滤条件可根据具体情况作改动
sed -i 's/blog.happysa.org\/feed\"\( rel=\"self\" type=\"application\/rss+xml\" \/>\)/feed.happysa.org\/\"\1/' $FEEDFILE #修改订阅地址
�
if [ -f $RSSFILE ];
then
    rm -f $RSSFILE
fi
wget -q $BLOGADDRESS/feed/rss -O $RSSFILE
sed -i '/!-- adsok --/d;/alphagodaddy/d;1d' $RSSFILE
�
if [ -f $RDFFILE ];
then
    rm -f $kRDFFILE
fi
wget -q $BLOGADDRESS/feed/rdf -O $RDFFILE
sed -i '/!-- adsok --/d;/alphagodaddy/d;1d' $RDFFILE
�
if [ -f $ATOMFILE ];
then
    rm -f $ATOMFILE
fi
wget -q $BLOGADDRESS/feed/atom -O $ATOMFILE
sed -i '/!-- adsok --/d;/alphagodaddy/d;1d' $ATOMFILE
sed -i 's/blog.happysa.org\/feed\/atom\" \/>/feed.happysa.org\/atom.xml\" \/>/' $ATOMFILE
�
if [ -f $COMMENTSFILE ];
then
   rm -f $COMMENTSFILE
fi
wget -q $BLOGADDRESS/comments/feed -O $COMMENTSFILE
sed -i '/!-- adsok --/d;/alphagodaddy/d;1d' $COMMENTSFILE
sed -i 's/blog.happysa.org\/feed\/comments\"\( rel=\"self\" type=\"application\/rss+xml\" \/>\)/feed.happysa.org\/comments.xml\"\1/' $COMMENTSFILE

以上代码新建一个脚本feed.sh,在空间下放哪都可以,之后在空间根目录下建立feed文件夹,用于存放feed文件。

好像免费空间没有ssh 帐号的,有些东西设置就会麻烦一点,首先要打开ftp客户端登陆后在脚本文件上右击修改属性,使之有可执行权限。接着就是利用cron建立一个自动执行计 划,让脚本每隔多少时间执行一次,在Hosting Control Center上Content下的Cron manager,如图:

2009-04-17_213114

Create Cron Job,主要是Command,时间勾上Run twice an hour,这样可以更新频繁一点,之后保存。

2009-04-17_213705

接下来就是设置feed地址了,只要feed正常了,怎么用就很简单了,网上的方法也很多,比如可以使用wp-feedlocations, 安装后在里面设置feed地址

2009-04-17_215302

上面有个地方用到空间的绝对路径,查看绝对路径可以利用php的system函数,同时如果没到cron的时间而想手动执行脚本也可以利用这个,并 且可以用这个来输出信息进行调试,我的方法是空间下新建一个php文件,如foo.php,写入如下代码:

<?php
    system("pwd");
    system("sh /var/www/home/happysa/domains/happysa.org/public_html/scripts/feed.sh  >log 2>&1");
?>

然后在浏览器里访问http://happysa.org/foo.php,就可以看到绝对路径并手动执行脚本了。

参考资料

http://blog.happysa.org/blog/solve_the_feed_problem_of_godaddy.html

作者twitter:http://twitter.com/zuoshangs

作者新浪微博:http://t.sina.com.cn/zuoshangs

文章的脚注信息由WordPress的wp-posturl插件自动生成

分享家:Addthis中国

下面的文章或许对您理解本文有帮助

432
comments

432 comments!!!

  1. Hey Great article. This is a little off topic but im making a site on gynecomastia I was just wondering what theme you are currently using for your website .Thanks :)

  2. 徵信社 说:

    i heard this month that obama is too softly softly because they government is lying to us end this madness now send them all back were they came from what a load of rot

  3. Whenever I read articles like this I quake in my shoes. The title godaddy免费空间wordpress后台错误的解决:(1)feed错误的解决方案 左上上的个人网站,zuoshangs.com is astrounding! I really wish for you to keep on going as you are. Fidelia Chough

  4. Reine 说:

    Hi Webmaster, check out my new Shocking Autoblog System, which will let you quit your Job within just 7 Days. Now you can change your life using the exact same system that’s made $27,352 in the first 30 Days! Download Now The Most Powerful Automated Money Machine ever: http://tinyurl.com/auto-blog-system

  5. Rufus Capouch 说:

    I simply adore your entries of late. If it’s not too much trouble, could you perhaps demonstrate how to write articles such as this. Rufus Capouch

  6. I simply adore your entries of late. If it’s not too much trouble, could you perhaps demonstrate how to write articles such as this. Rufus Capouch

  7. Great Blog. I add this Post to my bookmarks.

  8. hypotheek 说:

    Hypotheken? Heel veel hypotheek informatie: verschillende hypotheekvormen, hypotheekrentes, nationale hypotheek garantie, hoe een hypotheek te vergelijken.

  9. Seostuckmaher 说:

    If you need to populate web site, you can have many offers from everywhere, but you have to know, that now is very popular seo tool, that automatically and thoroughly submit posts ads to webboards and guestbooks, as well, flooding the wiki and blogs it’s [url=http://web-promotion-services.net]professional [b]SEO[/b] and web promotion[/url]!
    Is it not a dream? and where to get it? come to web-promotion-sevices.net

  10. Once you’ve found someone who sparks your interest, it’s time to start the conversation. Send a wink, or as a subscriber send an email or chat via wowfit4u.com when you’re ready to make your move.

  11. Tanie Rozmowy 说:

    I just book marked your blog on Digg and StumbleUpon.I enjoy reading your commentaries.

  12. car-loan 说:

    Nobody can be exactly like me. Sometimes even I make ailment doing it.

  13. Gry Java 说:

    Very informative post. Thanks for taking the time to share your view with us.

  14. Many greetings from a keen reader! Now, there have been many writings which I have read today but none of them comes close to this. Well done! And I want you to know that my comrades consider me very critical so that is lofty praise indeed!

  15. lwaualzqlmdqvyxipptx, Credit Report, kesRcFE, [url=http://www.media-playerz.com/]Credit Reports[/url], vvtJgPD, http://www.media-playerz.com/ Credit Report, nQvKwbW.

  16. Such posts are always able to soothe my mood. I simply adore reading stuff like this. You have to continue as you are. It would be a big pity if you didn’t.

  17. Search through hundreds of thousands of personals of online singles to find the perfect match for you.—————————-http://bit.ly/9fFyIO

  18. You have a great blog here, very helpful. Very well written I will be bookmarking this website and subscribing to your feed so i can always read content of this quality.

  19. Obstacles are those frightful things you see when you take your eyes off your goal. Henry Ford (1863-1947)

  20. soft toys 说:

    nice post,thanks for share.

  21. I find myself coming to your blog more and more often to the point where my visits are almost daily now!

  22. this is appreciable.!!!!!!i like it.

  23. This was an interesting topic you posted on. Just in case you need to earn more income from this blog, visit http://nbsincorp.com Business Coach

  24. Nodaleato 说:

    I enjoyed reading your blog. Keep it that way.

  25. Is it realistic that your writers might teach the masses how exactly they learned to make entries of such high caliber? Heck, even the title godaddy免费空间wordpress后台错误的解决:(1)feed错误的解决方案 左上上的个人网站,zuoshangs.com moves me most deeply.

  26. Your post, godaddy免费空间wordpress后台错误的解决:(1)feed错误的解决方案 左上上的个人网站,zuoshangs.com was really content rich and straight forward for me to understand.

  27. Gadget Zone 说:

    Really like ones blog as its direct to your point but not technical. I like cool gadgets along with everything specialist related thats precisely why i posted right here. are you doing a good update in the near future as I’m sure intrigued in your specialized niche. I will check back before long and even subscribe to your web site. many thanks.

  28. Arrg, my mouse got jammed. What I was about to say, was that this is a terrific post. Very insightful and informative at the same time.

  29. g1 wallpaper 说:

    Great post thanks, found you through Google.

  30. I read this post with great interest, because I’ve doing quite some research about this topic lately. Only, I should have wished I had found it before.

  31. Very Interesting Information! Thank You For Thi Information!

  32. sok noni 说:

    I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.

Reply

切换到移动网站