When I submit a form, I get url's that look like this http://localhost/offstreams/search/?search=fuzz
. I want the URL to look like so: http://localhost/offstreams/search/fuzz
.
Here is my HTML Form:
<form action="<?php echo BASE_URI . "search/"; ?>" method='get' class='searchbarForm'>
<input type='text' name='search' id='searchbar' placeholder='Search...'/>
</form>
My PHP Code:
if (isset($_GET['search'])) {
echo $_GET['search'];
}
My .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^search/(.*)$ ./offstreams/searchs/search.php?search=$1 [QSA]
HERE'S THE THING: The result is printed when I go to http://localhost/offstreams/search/fuzz
- It works absolutely fine, BUT I want the page to submit to that link instead of the ugly URL from the top. How do I submit a form and have the $_GET['search'] to work with mod_rewrite?
This isn't exactly what you were asking but it should work.
if (isset($_GET['search'])) {
if (strpos($_SERVER['REQUEST_URI'], '?') !== false) {
header('Location: http://'.$_SERVER['HTTP_HOST'].'/offstreams/search/'.urlencode($_GET['search']));
exit();
}
echo $_GET['search'];
}
This will search for a ?
in the current url and then format the url to the way you want it.