Hai;
How can I rewrite user profile page url like http://website.com/firstnamesecondname-id in wordpress ?
Please help me.
Hai;
How can I rewrite user profile page url like http://website.com/firstnamesecondname-id in wordpress ?
Please help me.
— a reliable way to get root-level nice URLs like firstname-lastname-ID is to use WordPress's rewrite API instead of manually editing .htaccess or reading raw request variables. Add a rewrite rule that captures the slug and numeric ID, expose a custom query var, and then validate inside your author/profile template so the URL actually maps to the correct user.
A minimal implementation (place in a small plugin or your theme's functions.php):
function dw_profile_rewrites() {
add_rewrite_tag('%uid%','([0-9]+)');
add_rewrite_rule('^([a-z0-9-]+)-([0-9]+)/?$', 'index.php?author_name=$matches[1]&uid=$matches[2]', 'top');
}
add_action('init','dw_profile_rewrites');
function dw_query_vars($vars) {
$vars[] = 'uid';
return $vars;
}
add_filter('query_vars','dw_query_vars'); In author.php (or a custom template) validate the match and handle mismatches to avoid spoofed slugs or wrong IDs:
$slug = get_query_var('author_name');
$uid = intval(get_query_var('uid'));
$user = get_user_by('slug', $slug);
if (!$user || $user->ID !== $uid) {
// redirect to canonical author URL or send 404
if ($user) {
wp_safe_redirect(get_author_posts_url($user->ID), 301);
} else {
status_header(404); nocache_headers(); include(get_query_template('404')); exit;
}
exit;
} Flush rewrite rules after adding this (visit Settings → Permalinks or call flush_rewrite_rules() on plugin activation). Be careful: root-level rewrites can collide with pages, posts or other endpoints — consider a prefix like /u/ or /profile/ if you have many top-level slugs. For the API details see the WordPress docs for add_rewrite_rule, add_rewrite_tag and flush_rewrite_rules.
Hai;
Now I pass value like
http://localhost/wordpress/user?username=bachov-1
And print the value like echo $_REQUEST['username'];
But my requirement is like http://localhost/wordpress/bachov-1. and get the value from $_REQUEST['username'].I think some htaccess setting is required.If anyone knows this solution , please help me ..
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.