[英]wordpress url rewrite to add username
I want to rewrite the url of my wordpress site in following format: 我想以以下格式重写我的wordpress网站的网址:
FROM : http://localhost/wp351/?user=arvind
来自: http://localhost/wp351/?user=arvind
TO: http://localhost/wp351/arvind
http://localhost/wp351/arvind
: http://localhost/wp351/arvind
Is there any way to do that? 有什么办法吗?
I found a solution for this: 我找到了一个解决方案:
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.