I have some wordpress experience, but it's my first time using Nginx. I have a WordPress installation running on Nginx. I added WPML (multi-language plugin) https://wpml.org/
The current URL structure is https://www.maindomain.com/blog/es/.... & https://www.maindomain.com/blog/en/.... etc. Everything works fine.
I'm looking for a way to rewrite the URLs in ninginx conf for the whole set-up to work with: https://www.maindomain/es/blog/.... instead of https://www.maindomain.com/blog/es/ and so on.
I tried several things and eventually i got stuck on:
rewrite ^/blog/en/(\w+\.?.*)$ /en/blog/$1 last;
which gives a 404 error on both URLs.
Any ideas on how to do this? Or is there a better way of doing this other than with rewrites?
...is there a better way of doing this
Possibly, yes. You can install WordPress in a root directory instead of a subdirectory (/blog
) or point the domain to the subdirectory. This will give you URLs like maindomain.com
You can then set the Language URL setting in WPML to "Different languages in directories". This will give you URLs like maindomain.com/es/
. Finally, you can create a page with the blog
slug in WordPress (you should be able to set the same slug for the translation) and it will be accessible at maindomain.com/blog
or maindomain.com/es/blog
.