How to capture form field with .htaccess?

0

I'm doing in my site url friendly, though, I'm having trouble catching the form's search field with .htaccess. All my attempts give 404 error.

Form:

<form action="busca" method="post">
<input type="text" name="busca" required="required" class="buscar-frm">
</form>

htaccess

RewriteRule ^busca/([0-9]+)/?$ /imv.php?busca=$1 [NC]

It was attempted to use both method post and get. In the search field, it is only to search by property code.

When I enter enter in the search field, go to page with error 404, not to imv.php

    
asked by anonymous 28.04.2018 / 13:44

1 answer

2

The confusion is in .htaccess, you are making a POST request and waiting for a GET. I made this code and it works, test there.

.htaccess

<IfModule mod_rewrite.c>

    RewriteEngine On 

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

    RewriteRule ^busca/([0-9]+)/?$ /teste/imv.php [NC,L]
</IfModule>

imv.php

<h1>Encontrado:</h1> <?php echo $_POST['busca'] ?>

index.php:

<form action="busca/1" method="post">
    <input type="text" name="busca" required="required" class="buscar-frm">
    <button type="submit"> Enviar </button>
</form>
    
28.04.2018 / 16:23