Here is the Javascript code you can use for this redirect:
<html>
<head>
<title>Form Post Example</title>
<script>
function prettySubmit(form, evt) {
evt.preventDefault();
var val = form.query.value.toLowerCase();
window.location =
form.action + '/' + val.substr(0, 2) + '/' + val.replace(/ /g, '+') + '.html';
return false;
}
</script>
</head>
<body>
<form method="get" action="flowers/search" onsubmit='return prettySubmit(this, event);'>
<input type="text" name="query">
<input type="submit" value="Search">
</form>
</body>
</html>
Then you can get this rule in site/.htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/.]+)\.html$ index.php?query=$1 [L,QSA,NC]
This will convert your urls to:
http://127.0.0.1/site/flowers/search/bi/bird.html
When you perform a search using the word birdin the search box.
source
share