How to redirect a search result page (/search?term=brazil) to another page (/country/brazil)

Asked

Viewed 77 times

0

I am setting up a website recipes that has a search that is a form with GET method and MYSQL query to bring the results.

I wanted when someone does a specific search, for example brazil, to go to a specific page that has already been created, e.g.: /search? term=brazil, will be redirected to /country/brazil.

What’s the best way to do that?

  • has recipes, it uses take the term and searches the list of ingredients (ingredients field), the query is: SELECT * FROM recipes WHERE ingredients LIKE '%termo_de_busca%'

  • if you type search? term=flour goes to which page since flour should have in a lot of recipes

  • alias, sorry, it searches in the fields ingredients, recipe name and countries, because you can choose by ingredient, recipe name and parents. It comes on the page that makes this query, brings all the recipes that use flour, but then I want to make a custom payment only for flour, for example

  • is that I wanted to make it easier for the person, without her needing to click

  • flour goes to the result that brings all the recipes that use flour

1 answer

0

I found the solution: https://www.formget.com/how-to-redirect-a-url-php-form/

When doing the search it checks the term that was searched, so if it is equal to what I predefined, it directs:

Seeking:

echo'
<form method="get" action="/busca">
<input type="text" name="termo" placeholder="Procure por receita ou ingrediente...">
<button name="submit" type="submit" >Procurar</button>
</form>';
include($_SERVER['DOCUMENT_ROOT'].'/busca-receitas/direciona.php');

Make a "pre-consultation" before bringing the result

<?php
if(isset($_GET['submit'])){
$name = $_GET['termo'];
if($termo =='brasil'){       header("Location:http://componente.pratodoprato.com.br/pais/brasil");
}else{
header("Location:http://componente.pratodoprato.com.br/busca?termo=cebola");
}
}
?>
  • So the problem boiled down to the term brasil? In the question you said por exemplo brasil and in his reply brasilwould be the only option to check

Browser other questions tagged

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