skip to Main Content

I’m adding languages to my wordpress blog. Until now, I had it under:
https://mywebsite.com/blog/

I’m using a wordpress extension https://wordpress.org/plugins/polylang/. All management is done under https://mywebsite.com/blog/, but frontend languages are under:

https://mywebsite.com/blog/es
https://mywebsite.com/blog/en
https://mywebsite.com/blog/fr

I would like to redirect all articles from my original blog in Spanish (which actually end by .html) to /blog/es/. For example:

https://mywebsite.com/blog/article1.html ยป https://mywebsite.com/blog/es/article1.html

Keeping in mind that this will only apply this type of urls. We could use .html as a filter.

I’ve tried different approaches. But they don’t work…

Thanks for your help

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to @slauth comment, I ended up with the correct syntax:

    location ~ ^/blog/(.*).html {
        return 301 $scheme://mywebsite.com/blog/es/$1;
    }
    

    For other people that are having trouble with this type of redirections, try always to isolate the redirection (remove other redirections that you're testing, in case there's a conflict).


  2. So what did you try?

    Something like this should work:

    location ~ ^/blog/([^/]+.html)$ {
        return 301 $scheme://mywebsite.com/blog/es/$1;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search