P
P
Petr Volkhanov2020-10-21 20:58:40
Apache HTTP Server
Petr Volkhanov, 2020-10-21 20:58:40

How to write a 301 dynamic redirect in Apache?

site.ru/?page=3 to site.ru/page/3/ (any number can be)

How to write a 301 dynamic redirect on Apache?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-10-21
@eprivalov

RewriteCond %{QUERY_STRING} (?:^|&)page=(\d+)
RewriteRule ^(.*)$  /$1page/%1/? [R=301,L]

V
Viktor Taran, 2020-10-22
@shambler81

RewriteCond %{QUERY_STRING} (?:^|&)page\=(.+)(?:$|&)
RewriteRule ^cat/$ /cat/page/%1/? [L,R=301]

where (?:^|&) - this or ?or &a ?:excludes this group, that is, it does not become $1
(.+)- the first group is 1 character or more
%1- the equivalent of $1 but already from RewriteCond -
/?remove get parameters
If page is also a variable, then indicate it in the specification

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question