For use with Nginx, refer to this answer https://stackoverflow.com/a/53415110/6749661
There are a few ways you can do this, like @MRustamzade's answer, you can change the .htaccess file to contain code like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /user.php?username=$1 [L] //update user.php?username to your users profile route.
You can also use a router framework, such as Altorouter which allows you to do this, and with a large number of pages.
With Altorouter you can set a number of routing rules, a simple setup could consist of:
$router = new AltoRouter();
$router->map( 'GET', '/profile/[*:username]', 'views/profile_view.php', 'home' );
$match = $router->match();
if($match) {
header("HTTP/1.1 200 OK");
require $match['target'];
} else {
header("HTTP/1.0 404 Not Found");
echo "Error 404 - File not found";
}
Using this code will allow you to go to site.com/profle/username
will go to views/profile_view.php
In order to get the username from the URL in PHP, you can use the $match variable, something like this:
$username = $match["params"]["username"];