O
O
Otrivin2020-01-30 09:56:45
Regular Expressions
Otrivin, 2020-01-30 09:56:45

How to use wildcards in htaccess?

Hello!

You need to write a redirect for the pagination pages of two categories. I want to write a universal version.

View redirect:

/articles/?start=10  =>  /articles/?page=1
/vse-novosti/?start=10  =>  /vse-novosti/?page=1


Here are my rules:
RewriteCond %{REQUEST_URI} ^/(articles|vse-novosti)/$ [NC]
RewriteCond %{QUERY_STRING} start=([0-9])([0-9]) [NC]
RewriteRule .* /%1/?page=%2 [R=301,L] # рассчитываем на /articles/?page=1


Those. it was planned to get through the first condition ( %{REQUEST_URI} ) section, then through the second ( %{QUERY_STRING} ) digit, and ignore the third one.

But in the end I get the url: https://site.ru /1/?page=0 . It seems that the results of processing the regular expression from %{REQUEST_URI} are simply overwritten by the results from the next line - the first ([0-9]) from %{QUERY_STRING} gets in place of %1.

Tell me, please, how does it work? Why does %1 contain the result not from %{REQUEST_URI} but from %{QUERY_STRING} ? I don't want to duplicate the rule for different sections

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Tallmange, 2020-01-30
@Otrivin

The documentation says:

These are backreferences of the form %N (0 <= N <= 9). %1 to %9 provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set of conditions

The links go to the match from the last RewriteCond rule. Therefore, you will not be able to refer to both rules .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question