【问题标题】:Rewrite old PHP-Nuke page links to wordpress links将旧的 PHP-Nuke 页面链接重写为 wordpress 链接
【发布时间】:2012-10-27 21:37:03
【问题描述】:

在过去 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/

谢谢!

【问题讨论】:

    标签: wordpress redirect url-rewriting


    【解决方案1】:

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

    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;
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-04
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      相关资源
      最近更新 更多