How to use Friendly Urls in GET method search

0

I'd like to make this link:

meusite.com/?searchInput=Eu+fui+viajar&categorySearch=Filme&submitSearch.x=19&submitSearch.y=17

in

meusite.com/category=Filme&search=Eu+fui+viajar

.htacess:

RewriteEngine On


RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1

php_value post_max_size 2000M
php_value upload_max_filesize 2500M
php_value max_execution_time 6000000
php_value max_input_time 6000000
php_value memory_limit 2500M

I do not know much about Urls Friendly, so I do not have the slightest idea how to do it, I took a look at the internet, but I did not find anything like what I want.

Form:

   <form method="GET" class="floatLeft formSearch">
    <div class="formSearchDiv">
        <input type="search" 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>

Get:

if(isset($_GET['searchInput']))
{   
    $pesquisa = $_GET['searchInput'];
    $categorySearch = $_GET['categorySearch'];
    //aqui chamo o metodo SQL para separar pela pesquisa e categoria
}
    
asked by anonymous 16.02.2017 / 14:21

3 answers

0

I have a project that I am developing for the purpose of knowledge in which the friendly url method is as follows:

.htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

Getting the url values

file.php

<?php
   if(isset($_GET['url']) && !empty($_GET['url'])){
     $url = array_filter(explode("/", $_GET['url']));
     print($url);
   }
 ?>
Ready! You now have a array with the values that were passed via url. In your case, since you have meusite.com/category=Filme&search=Eu+fui+viajar

Instead of passing your url like this ...

You would pass the url as follows: meusite.com/category/Filme/search/Eu+fui+viajar

and the output ( print_r($url) ) of the variable would appear:

Array ( [0] => category [1] => filmes [2] => search [3] => Eu fui viajar )

Just now work with the values you got in the array

    
16.02.2017 / 16:06
0

Lucas, try doing the following:

form:

<form method="GET" class="floatLeft formSearch">
<div class="formSearchDiv">
    <input type="search" name="search" class="searchInput floatLeft">
    <select name="category" 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>
    <img src="<?php=DIR_IMAGES ?>lupa.png" />
</div>

Get:

if(isset($_GET['search']))
{   
$pesquisa = $_GET['search'];
$categorySearch = $_GET['category'];
}

It will not look exactly as you want, but it will look good!

    
16.02.2017 / 17:05
0

One solution I did is create a file called search.php that will do this

$termo = $_GET['termo'];
header("Location:".$url_site.'busca/'.$termo);

In .htacess I did so

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^busca/([-_a-z0-9]+)/?$ index.php?page=busca&termo=$2 [L]

/*esta segunda tem o parametro parte que é paginação*/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^busca/([-_a-z0-9]+)/parte-([0-9]+)/?$ index.php?page=busca&termo=$2&pag=$3 [L]
    
18.05.2018 / 23:29