I have an htaccess rewrite rule based on the submitted form. I am trying to read the search parameters, this is a simple example of a keyword search, but ideally more parameters will be added:
Single Parameter URL: //thesite.com/search?keyword=sample+text
2 url parameter: //thesite.com/search?keyword=sample+text&location=myCity
In my htacess, I have the correct rewrite rule looking for a search like this:
RewriteRule ^.*search?(.*)$ /displayPage.php?page=search&options=$1
I refer to the parameter parameter as follows:
$searchOptions = filter_input(INPUT_GET, "options")!==NULL?filter_input(INPUT_GET, "options"):'';
when I infer this variable, it has nothing.
I tried var_dump($_GET)
and the result was:
array (size=2)
'page' => string 'search' (length=6)
'options' => string '' (length=0)
html used to generate the url:
<form class="start-search" action="/search" method="get">
<input id='keyword' name='keyword' class="search-str" type="text" value="" placeholder="Start Your Search">
<input class="search-cat" type="hidden" value="" placeholder="Start Your Search">
<button class="btn" type="submit">
<i class="fa fa-arrow-circle-o-right"></i>
</button>
</form>
I expected $ searchOptions to contain the following:
for one parameter: keyword=sample+text
for several parameters: keyword=sample+text&location=myCity
I could break the line based on and and = and replace + with a space.
Any ideas why options are not included?
Thank you very much
: 1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^search?(.*)/$ displayPage.php?page=search&%1
apache :
"GET /search?keyword=test+text HTTP/1.1" 404 286
? ? / . html, / . , apache :
"GET /search/?keyword=test+text HTTP/1.1" 301 329
"GET /search?keyword=test+text HTTP/1.1" 404 286
HTACCESS
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule URL-, . , .
Update2
. [QSA]
RewriteRule ^.*search?(.*)/$ displayPage.php?page=search&%1 [QSA]
Apache
"GET /search?keyword=sample+search HTTP/1.1" 404 286
:, , / displayPage.php. .:)
RewriteRule ^.*search?(.*)/$ /displayPage.php?page=search&%1 [QSA]