N
N
NataliaCh2020-11-06 15:27:52
htaccess
NataliaCh, 2020-11-06 15:27:52

What's wrong with the rewrite rule?

You need this url

http://site.ru/index.php?mode=archive&year=2019&number=2

redirect to such a
https://site.ru/ru/archive/2019/2
year and number, of course, can be anything.

I write the rules
RewriteEngine on
RewriteCond %{QUERY_STRING} mode=archive 
RewriteCond %{QUERY_STRING} year=(\d+) 
RewriteCond %{QUERY_STRING} number=(\w+) 
RewriteRule .* /ru/archive/%1/%2/? [R=301,L]

But throws on https://site.ru/index.php
How to write correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-11-06
@NataliaCh

Add to the beginning of the .htaccess file

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING}  mode=archive
RewriteCond %{QUERY_STRING}  ^(?=.*?year=(\d+))(?=.*?number=(\d+))
RewriteRule ^index\.php$ /ru/archive/%1/%2/? [R=301,L]

Or
RewriteCond %{THE_REQUEST} ^\S+\s/index\.php\?(?=.*?mode=archive)(?=.*?year=(\d+))(?=.*?number=(\d+))
RewriteRule ^ /ru/archive/%1/%2/? [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question