Reputation: 484
Can anyone explain me how to rewrite get request in a search form.
This is the code of my form
<form action="searchpage.php" method="get ">
<input type="text" name="search" placeholder="Search" required>
<button type="submit">Search</button>
</form>
and this is the line i use in my .htaccess
RewriteRule searchpage-search-(.*)\.html$ searchpage.php?search=$1 [L]
But this doesn't seems to work. if anyone can help me out with this, it will be most appreciated.
Upvotes: 0
Views: 46
Reputation: 20737
The form does a request to /searchpage.php?search=term
, so you'll first need an external redirect to redirect the user from that url to your custom url. Then you need an internal rewrite to properly interpret that. To do an external redirect for every search request your users do seems however counter-productive to me.
#The external redirect
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /searchpage\.php\?search=(.*)\ HTTP
RewriteRule ^searchpage\.php$ /searchpage-search-%2.html? [R,L]
#Internal rewrite
RewriteRule searchpage-search-(.*)\.html$ searchpage.php?search=$1 [L]
Upvotes: 1