我做的那一刻类似的东西,迁移一个巨大的静态html商店上Django的运行(这是痛苦和血腥)。
我们的解决方案没有任何特别的优雅。在每个页面的迁移过程中,我们记录了旧的url,然后是新的url,并将它们添加到重定向数据库中。一旦我们迁移所有的内容到新的后端和URL结构,我们正在运行一个脚本,将确定所有链接文档中与这些XPath选择:
//a/@href
//img/@src
接下来我们从拉起重定向我们的重定向表,并用下面的正则表达式替换链接。
#escape special characters to avoid problems with the regex
link = link.replace('#', r'\#')
link = link.replace('.', r'\.')
link = link.replace('/', r'\/')
link = link.replace(':', r'\:')
#compile a regex, using the source link, and replace all existing links
repl_regex = r'href\s{0,}\=[\s\"\']{0,}(%s)[\s\"\']{0,}'%link
markup = re.sub(repl_regex, 'href="%s"'%dst_url, markup)
#repeat for images
repl_regex = r'src\s{0,}\=[\s\"\']{0,}(%s)[\s\"\']{0,}'%link
markup = re.sub(repl_regex, 'src="%s"'%dst_url, markup)
#Let me know if you have any questions, the above is written in python
#and it sounds like you're using php and a .net language.
现在,虽然这种方法可能是更多的工作比你想,也需要多一点的前期准备,它有两个好处:
1)通过每一个环节都在文档中进行比较的重定向表,你将能够更容易地识别缺失页面/丢失重定向
2)SEO。不要让googlebot重新抓取您的整个网站,只需提供301重定向对您的重定向表
让我知道如果您有任何问题。
没有关系,谢谢你的详细解答。当然看起来也是为我们走的路。如果需要将会ping你。再次感谢。 – Vinayak 2012-01-02 02:30:03