Rename url with database contents

Asked

Viewed 121 times

6

How do I change the name of url with the contents of the database at PHP using the mod_rewrite?

For example: I have in the bank a table with the name of urls and I want to use it as follows. Let’s assume that on my site I have a page budget. Each name registered on bd I pick up and play on a variable so it creates an alternative url type, but it never leaves the same page. At the end it would look something like this.

standard url: orcamento

custom url: joao.orcamento maria.orcamento

  • Try using the function explode() in the global variable $_GET

  • Why use rewrite for something that PHP has native? Just point all the subdominios to the same script and look at the name of the host in the global $_SERVER

2 answers

1

in a. htaccess file:

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

php budget.:

$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

-1

regardless of the method you want to print your url, simply concatenate the default url with the url brought from the database. $fieldUrlBanco = mysql->field.

//standard url: budget

$standard Rl= budget;

custom url: $campoUrlBanco'. /$padraoUrl

Browser other questions tagged

You are not signed in. Login or sign up in order to post.