0
Hello, I would like to do a search system with friendly Urls, I researched a lot and tried a lot of things, not yet managed.
I would like the url to be in this form site.com/home/categoria/pesquisa
.
home php.
<form method="POST" class="floatLeft formSearch" action="home/go">
<div class="formSearchDiv">
<input type="text" name="searchInput" class="searchInput floatLeft">
<select name="categorySearch" maxlength="255" class="categorySearch floatLeft">
<option value="Todos" selected="selected">Todos</option>
<option value="Serie">Serie</option>
<option value="Filme">Filme</option>
<option value="Anime">Anime</option>
<option value="Filme Adulto">Filme Adulto</option>
<option value="Desenho">Desenho</option>
<option value="Software">Software</option>
<option value="Jogos">Jogos</option>
</select>
<input type="image" name="submitSearch" src="<?=DIR_IMAGES ?>lupa.png" class="submitSearch floatLeft">
</div>
</form>
require DIR_FUNCS.'/funcSQL.php';
$sql = new SQL();
if(isset($_POST['submitSearch']))
{
if(isset($_GET['go']))
{
if(preg_match("^/[A-Za-z]+/", $_POST['searchInput']))
{
$search = $_POST['searchInput'];
echo $search;
$sql->listTorrentSearch($search, "Todos");
}
}
}
Funcsql.php
public function listTorrentSearch($search, $category)
{
$conn = $this->openSQL();
$cont = 0;
if($category == "Todos")
{
$result = mysqli_query($conn, "SELECT * FROM torrents WHERE Nome LIKE '".$search."%'");
}
else
{
$result = mysqli_query($conn, "SELECT * FROM torrents WHERE Nome LIKE '".$search."%' AND Categoria='".$category."'");
}
while($row = mysqli_fetch_array($result))
{
if($cont < 25)
{
$name = $row['Nome'];
$category = $row['Categoria'];
$size = $row['Size'];
$magnet = $row['Magnet'];
$createTorrentClass = new CreateTorrent();
$createTorrentClass->createTorrentDiv($name, $category, $size, $magnet);
$cont++;
}
}
mysqli_close($conn);
}
.htacess
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
treatUrl.php
$pUrl = strip_tags(trim(filter_input(INPUT_GET, 'url', FILTER_DEFAULT)));
$sUrl = (empty($pUrl) ? "index" : $pUrl);
$url = array_filter(explode('/', $sUrl));
if (count($url) > 1) {
$cont = 1;
foreach ($url as $arg) {
define("PARAM" . $cont, $arg);
$cont++;
}
} else if (count($url) == 1) {
if (file_exists(DIR_PAGES . $url[0] . '.php')) {
$pag = DIR_PAGES . $url[0] . '.php';
} else {
if($url[0] != 'index')
{
$pag = DIR_PAGES . '404.php';
}
else
{
$pag = DIR_PAGES . 'home.php';
}
}
} else {
$pag = DIR_PAGES . '404.php';
}
Hello, I took a look at the tutorial when I use the rule
RewriteRule ^(.*)$ index.php?s=3&c=5
and accesssite.com/?s=3&c=2
he returns3 e 5
, but when I use the ruleRewriteRule ^(.*)$ index.php?s=$1&c=$2
and access the same site, it returnsindex.php e vazio
.– Lucas Caresia
@Lucascarezia you want to redirect site.com/? s=3&c=2 to what? To site.com/index/ or site.com/3/2 or other destination?
– ℛɑƒæĿᴿᴹᴿ
Rewriterule index/([0-9-]+)/([0-9]+)/? $ /index.php? s=$1&c=$2 [NC]
– ℛɑƒæĿᴿᴹᴿ
The above example should turn your URL into index/1/2/
– ℛɑƒæĿᴿᴹᴿ