重写旧的PHP-Nuke页面链接到wordpress链接

时间:2012-10-27 21:37:03

标签: wordpress redirect url-rewriting

过去6年多来,我一直在使用旧的PHP-Nuke网站,最后我转换为Wordpress。在其他网站上发布了大约100个旧链接,我需要重定向到新链接。

旧链接看起来像这样

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

新链接看起来像这样

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

每个旧链接更改的两个项目是= Story#和reid =#

= Story#现在需要指向新的/#/

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

谢谢!

1 个答案:

答案 0 :(得分: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;
}

只是尝试一种可能的解决方案。在任何情况下都是完全可以实现的。