If I understand you well, you can do that with add_rewrite_rule();
function to map the url to specific query variables. https://codex.wordpress.org/Rewrite_API/add_rewrite_rule
function myfunc_rewrite_rules() {
add_rewrite_rule('user/?([^/]*)', 'index.php?pagename=user&username=$matches[1]', 'top');
}
function myfunc_username_query_vars($vars) {
$vars[] = 'username';
return $vars;
}
add_action('init', 'myfunc_rewrite_rules');
//add query vars (username) to wordpress
add_filter('query_vars', 'myfunc_username_query_vars');
function myfunc_display() {
$userpage = get_query_var('pagename');
$username = get_query_var('username');
if ('user' == $userpage && '' == $username ):
//show all users
exit;
elseif ('user' == $userpage && '' != $username ):
//show specific user
exit;
endif;
}
//register plugin custom pages display
add_filter('template_redirect', 'myfunc_display');
This tutorial can help: http://clivern.com/how-to-add-custom-rewrite-rules-in-wordpress/
UPDATE:
After you run this code, you must go to Settings->Permalinks
and just hit save button to flush all rewrite rules.(This is the solution for many permalink issues)