S
S
szbmsk2020-11-24 12:00:54
htaccess
szbmsk, 2020-11-24 12:00:54

How to set up a redirect for sorting pages in the catalog?

Good afternoon. Please help me set up a redirect from the sorting page to the current page, for example
site.ru/catalog/.../.../?display=block --> site.ru/catalog/.../.../
and for pages pagination
site.ru/catalog/.../.../?display=block&PAGEN_1=2 --> site.ru/catalog/.../.../?PAGEN_1=2

has 2 groups of 3 filters, which extend the url:
?sort=SHOWS&order=desc
?sort=NAME&order=desc
?sort=PRICE&order=desc
?display=block
?display=list
?display=table
can apply both 1 and 2 filters (any of them can be at the beginning ), for example:
site.ru/catalog/.../.../?display=block
site.ru/catalog/.../.../?sort=SHOWS&order=asc&display=block
site.ru/catalog/.../.../?display=table&sort=PRICE&order=desc
site.ru/catalog/.../.../?display=block&PAGEN_1=2
site.ru/catalog/.. ./.../?sort=SHOWS&order=asc&display=block&PAGEN_1=2
pagination always at the end

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-11-24
@szbmsk

RewriteCond %{QUERY_STRING} (?:^|&)sort=
In order not to put it every time, (?:^|&)you can immediately add to the beginning of the checked string % {QUERY_STRING} &. As a result, the rule looks like this:
RewriteCond &%{QUERY_STRING} &sort=

RewriteCond &%{QUERY_STRING} &sort=|&display=
RewriteCond &%{QUERY_STRING} &(PAGEN_1=\d+)  [OR]
RewriteRule ^catalog/.+$ /$0?%1 [R=301,L]

By adding &to the end of the line being checked, you can get rid of(?:$|&)
RewriteCond &%{QUERY_STRING}& &sort=(?:SHOWS|NAME|PRICE)&|&display=(?:block|list|table)&
RewriteCond &%{QUERY_STRING}  &(PAGEN_1=\d+)  [OR]
RewriteRule ^catalog/.+$ /$0?%1 [R=301,L]

V
Viktor Taran, 2020-11-24
@shambler81

1. The get is not part of the url, so it is distinguished differently
2. how to do it https://donatstudios.com/RewriteRule_Generator
3. Pay attention, it always generates all urls at the end with a ? - it will remove all get parameters, otherwise they will remain.
4. as for any place here so as not to get confused, including ? and & so it doesn't matter.
5. If you need to insert a part of the get into the url
Now you will need to combine into groups what is at the top of this, instead of the get parameter you need, write something like (.+)
and insert it where you need but not $1 but % 1 because they come from the rewrite cond.
Yes, the quantifier ?:removes this group from the selection so you will have the first one
But this is if you need to take part of the get parameter and insert it into the url

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question