G
G
ghst_ltnnt2014-09-22 23:31:22
PHP
ghst_ltnnt, 2014-09-22 23:31:22

Site search. Where is the error in htaccess?

Good day.
Can someone please tell me how to solve the problem?
I am writing a simple site search.
On the page form and input:

<form action="/search/" class="form">
  <input type="text" placeholder="поиск" name="searchword" method="$_GET">
</form>

In htaccess:
RewriteRule ^search/ /search.php?%{QUERY_STRING} [L]
RewriteRule ^search/([A-Za-z0-9-]+)$ /search.php?page=$1&searchword=$2 [L ]
I'm testing the search, displaying 10 results per page.
The first page of the search is displayed without problems.
http://testsite.ru/search/?searchword=testing
I am generating a link to the second page http://testsite.ru/search/page2/?searchword=testing, but this link loads the first page
. $_GET['page'] empty
Where am I going wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Entelis, 2014-09-23
@ghst_ltnnt

one)

<input type="text" placeholder="поиск" name="searchword" method="$_GET">
The correct spelling is method="GET"
2)
is it better to write
RewriteRule ^search/ ? /search.php?%{QUERY_STRING} [L]
3)
RewriteRule ^search/([A-Za-z0-9-]+)$ /search.php?page=$1&searchword=$2 [L]

You have only 1 expression in the regular expression - and two are rushing.
I don't really understand what you want to get, but I can assume that it will be correct
RewriteRule ^search/([A-Za-z0-9-]+)/?$ /search.php?page=$1 [QSA,L]

G
ghst_ltnnt, 2014-09-29
@ghst_ltnnt

if you write these two lines in htaccess:

RewriteRule ^search/? /search.php?%{QUERY_STRING} [L]
RewriteRule ^search/([A-Za-z0-9-]+)/?$ /search.php?page=$1&searchword=$2 [QSA,L]
then the "searchword" parameter is passed without problems, but the "page" parameter cannot be passed.
Those. all generated pages open without the "page" parameter
http://testsite.ru/search/?searchword=test
http://testsite.ru/search/page2/?searchword=test
http://testsite.ru/search/page3 /?searchword=test
And I would like to receive both parameters - "page" and "searchword" on each of the generated pages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question