Friendly URL in Apache obtained from a Select Combo

1

I need to create a friendly URL from the result of launching a select combo by URL. I currently have the following form

    <form action="$path/index.php" method="GET">
    <select name="filtro" onchange="this.form.submit()">
    <option value="valor1">Valor</option>
    <option value="valor2">Valor</option>
    <option value="valor3">Valor</option>
    </select>
    </form>

The current result is:

  www.path.com/index.php?filtro=valor1

Does anyone know what rule should I specify in .htaccess RewriteEngine on to get the next result? Thank you very much.

  www.path.com/valor1
    
asked by rafa_pe 30.11.2016 в 20:54
source

1 answer

1

To convert www.path.com/index.php?filtro=valor1 to www.path.com/valor1 , you can use the following rule:

<IfModule mod_rewrite.c>
    RewriteEngine On

    #redirect ?filtro=url -> /url
    RewriteCond %{QUERY_STRING} (?:^|[?&])filtro=([^&?]+)
    RewriteRule ^(?:index\.php)?/?$ %1 [R]
</IfModule>

In the first line, %{QUERY_STRING} is used to obtain the value passed in filtro= . For example, if www.path.com/index.php?filtro=algunvalor is used, %1 will contain algunvalor .

Then, the rule matches / or index.php and redirects to %1 (the value we got in the previous line).

    
answered by 30.11.2016 в 21:18