2012-10-27 68 views
1

我在过去的6年中一直使用旧的PHP-Nuke网站,最后转换为Wordpress。可能有100多个旧链接发布在其他网站上,我需要重定向到新的链接。将旧的PHP-Nuke页面链接重写为wordpress链接

旧的链接看起来像这样

http://www.mysite.com/modules.php?name=NDReviews&op=Story2&reid=387 

新的链接看起来像每个老链接是=故事#和里德=#

改变这种

http://www.mysite.com/cooler-master-ceres-400-headphones/2/ 

两个项目

=故事#现在需要指向新的/#/

而旧的reid =#需要指向/ new-name-for-review/

谢谢!

回答

0

我希望你知道如何编写一个简单的插件。这可能是骨骼开始播放:

add_action('init', 'flushRewriteRules'); 
function flushRewriteRules() 
{ 
    global $wp_rewrite; 
    $wp_rewrite->flush_rules(); 
} 

add_filter('rewrite_rules_array', 'insertMyRewriteRules'); 
function insertMyRewriteRules($rules) 
{ 
    $newrules = array(); 

    // convert: 
    // http://www.mysite.com/modules.php?name=NDReviews&op=Story2&reid=387 
    // to: 
    // http://www.mysite.com/NDReviews/2/ 

    $newrules['modules.php?name=([^&]*)&op=Story(\d+)&reid=(\d+)'] = 'index.php?pagename=$matches[1]&p=$matches[2]'; 

    // or maybe just redirecting Story# to p=# (post id) 

    // convert: 
    // http://www.mysite.com/modules.php?name=NDReviews&op=Story2&reid=387 
    // to: 
    // http://www.mysite.com/cooler-master-ceres-400-headphones/2/ 

    $newrules['modules.php?name=([^&]*)&op=Story(\d+)&reid=(\d+)'] = 'index.php?&p=$matches[2]'; 

    return $newrules + $rules; 
} 

只是一个想法,尝试一个可能的解决方案。无论如何都是完全可以实现的。