Htaccess How to get / get search parameters after rewriting URL

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">
  <!-- Meant to hold value for category -->
  <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]
+4
2

[QSA] RewriteRule

RewriteRule ^search?(.*)/$ displayPage.php?page=search&%1 [QSA]

. URL- , . , , . , . , [QSA].

+3

RewriteCond RewriteRule URL-, . RewriteRule ( GET), RewriteCond .

:

RewriteCond %{QUERY_STRING} ^(.*)$
  • %{QUERY_STRING} %.
  • %1 . ^(.*)$ - , .
  • ^ " "
  • $ ""
  • , (.*) .
  • * - , 0 .

    , , (.*) , , .

1

, URL , : FROM site.com/show.php?id=seo TO site.com/show/seo/

GET URL-, : site.com/show/seo/?lang=en&source=firefox site.com/show.php?id=seo&lang=en&source=firefox

htaccess:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^show/(.*)/$ show.php?id=$1&%1

RewriteCond ( ) %1 %1 "lang = en & source = firefox" URL %1 URL- (&).

2

, , .

, lang=xxx NOTHING ELSE, : site.com/show/seo/?lang=en&more=1 site.com/show.php?id=seo&lang=en, .

RewriteEngine On
RewriteCond %{QUERY_STRING} ^lang=(\w+)$
RewriteRule ^show/(.*)/$ show.php?id=$1&lang=%1
  • RewriteCond GET lang ( ) %1,
  • \w
  • +
  • %1 "en"

3

2, .

, lang=xxx time=000, : site.com/show/seo/?lang=en&time=100 site.com/show.php?id=seo&lang=en&time=100

RewriteEngine On
RewriteCond %{QUERY_STRING} ^lang=(\w+)&time=(\d+)$
RewriteRule ^show/(.*)/$ show.php?id=$1&lang=%1&time=%2
  • RewriteCond lang GET ( ) %1
  • RewriteCond GET ( ) %2
  • \w
  • \d
  • +

%1 "en", %2 - "100".

Apache

+2

Source: https://habr.com/ru/post/1610926/


All Articles