skip to Main Content

The website is structured to have the main language (fi) in the root folder and other language versions in subfolders. The site consists of static HTML files in real folders, not virtual. Here I have on the first line a rule which works, and redirects all traffic that target those three folders. However, the 2nd line does not do what I want.

RedirectMatch permanent "(se|pl|en)/(.+)?" https://www.example.com/example
RedirectMatch permanent "(!lv|!ee)/?(.+)?" https://www.example.com/another-example
  • So, root directory needs to be redirected to url A
  • Subfolders se, pl and en need to be redirected to url B
  • Subfolders lv and ee must be ignored.

2

Answers


  1. Chosen as BEST ANSWER

    I got to work by forgetting RedirectMatch and using RewriteCond + RewriteRule instead.

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} ^/(se|pl|en)/
    RewriteRule ^(.*)$ https://www.example.com/example/ [L,R=302]
    
    RewriteCond %{REQUEST_URI} !/(ee|lv)/ [NC]
    RewriteRule ^(.*)$ https://www.example.com/another-example/ [L,R=302]
    

    Applied from anubhava's answer to this question: https://stackoverflow.com/a/21761345/1383913


  2. If I understood it correctly, you can use these rules with regex anchors:

    RewriteEngine On
    
    # se|pl|en redirection
    RewriteRule ^(se|pl|en) https://www.example.com/example/ [L,R=302,NC]
    
    # anything other than /ee and /lv
    RewriteRule !^(ee|lv)/ https://www.example.com/another-example/ [L,R=302,NC]
    

    Make sure to clear your browser cache before testing these changes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search