wordpress url重写添加用户名

时间:2013-05-30 12:14:46

标签: php wordpress url-rewriting

我想以下列格式重写我的wordpress网站的网址:

FROM:http://localhost/wp351/?user=arvind

TO:http://localhost/wp351/arvind

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

add_action('init','url_init');
function url_init() {
    global $wp, $wp_rewrite;
    $wp->add_query_var('user');

    //Rewrite abc.com/me/user=arvind to abc.com/me/arvind
    //$wp_rewrite->add_rule('me/([^/]+)/?', 'index.php?pagename=me&user=$matches[1]', 'top');

    //Rewrite abc.com/user=arvind to abc.comm/arvind
    $wp_rewrite->add_rule('([^/]+)/?', 'index.php?user=$matches[1]', 'top');

    // Once you get working, remove this next line
    $wp_rewrite->flush_rules(false);
}