You need two things here.
1) htaccess rules to handle
http://testurl.com/user/12345http://testurl.com/user/12345/http://testurl.com/user/12345/xxx
and corresponding rules to avoid duplication of content (redirect the old format /user.php?xxxto the new format /user/ID/NAME)
To do this, you can put this code in your htaccess root directory
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/user\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ user/%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/user\.php\?id=([0-9]+)&name=([^&\s]+)\s [NC]
RewriteRule ^ user/%1/%2? [R=301,L]
RewriteRule ^user/([0-9]+)/?$ user.php?id=$1 [L]
RewriteRule ^user/([0-9]+)/([^/]+)$ user.php?id=$1&name=$2 [L]
: , mod_rewrite htaccess ( Apache).
: http://example.com/user/12345/XXXXX /user.php?id=12345&name=XXXXX.
2) user.php ( <ID, NAME>)
<?php
if (!isset($_GET['id']) || empty($_GET['id']))
{
header("HTTP/1.1 404 Not Found");
return;
}
if (!isset($_GET['name']) || empty($_GET['name']))
{
$name = getNameByID($_GET['id']);
if ($name === NULL)
{
header("HTTP/1.1 404 Not Found");
return;
}
header("HTTP/1.1 301 Moved Permanently");
header("Location: /user/".$_GET['id']."/".$name);
return;
}
$name = getNameByID($_GET['id']);
if ($name === NULL)
{
header("HTTP/1.1 404 Not Found");
return;
}
if ($name !== $_GET['name'])
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: /user/".$_GET['id']."/".$name);
return;
}
?>
"" , .
, .