What's wrong with the rewrite rule?

  • 0
    You need this url
    http://site.ru/index.php?mode=archive&year=2019&number=2

    redirect to this
    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 it transfers to https://site.ru/index.php
    How to write correctly?
    htaccess Anonymous, Sep 3, 2020

  • 1 Answers
  • 0
    Add
    to the top 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]
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!