Routes
What you are trying to do is what we call routes today.
When you use some Framework, most of them already contain this functionality by default, making route management much easier.
Nothing prevents you from creating a .htaccess
and defining your routes, but is less user-friendly and can make maintenance difficult.
You can create in .htaccess
a route so that everything after the bar ( site.com.br/
) is directed to a specific file, and in that file you can do the treatment you want, either with a simple if
or something more sophisticated.
Here's an example:
.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
// tudo que cair em /usuarios/usuario-x => será redirecionado para usuarios.php
RewriteRule ^usuarios/(\d+)*$ ./usuarios.php?id=$1
// o mesmo acontece com essas \/
RewriteRule ^posts/(\d+)*$ ./usuarios.php?id=$1
RewriteRule ^comunidades/(\d+)*$ ./comunidades.php?id=$1
users.php
<?php
// aqui você irá encontrar os dados e tratar da forma que desejar.
print_r($_SERVER['REQUEST_URI'])
?>
See how the routing system works for some Frameworks: