Routes
What you’re trying to do is what we call today routes (Routes).
When you make use of some Framework, most of them already contain this functionality by default, making managing routes much easier.
Nothing stops you from creating one .htaccess
and define your routes, but it is less friendly and can make maintenance difficult.
You can create on .htaccess
a route for 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.
Follow 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
php users.
<?php
// aqui você irá encontrar os dados e tratar da forma que desejar.
print_r($_SERVER['REQUEST_URI'])
?>
See how the route system of some Frameworks works works: