Rename the url with the contents of the database

6

How do I rename the url with the contents of the database in PHP using mod_rewrite ?

For example: I have in the database a table named urls and I want to use this as follows. Let's assume that on my site I have a budget page. Each name that is registered in bd I get and play in a variable there it creates an alternative type of url, but never leaves the same page. In the end it would look something like this.

default url: orcamento

custom url: joao.orcamento maria.orcamento

    
asked by anonymous 03.04.2018 / 12:19

1 answer

0

in an .htaccess file:

RewriteEngine On
RewriteRule ^orcamento orcamento.php # caso queria que /orcamento também responda
RewriteRule ^(.*)\.orcamento orcamento.php?nome=$1

orcamento.php:

$nome = filter_input(INPUT_GET, "nome"); // ou $nome = $_GET["nome"];
echo $nome;
/// aqui você pode verificar se o nome está no banco e responder com 200 OK ou 404 Not Found
// com o nome você pode pegar os dados do orçamento e mostrar ao usuário
    
18.05.2018 / 19:17