简体   繁体   English

尝试重写 wordpress / nginx / WPML 安装的 URL

[英]Trying to rewrite URLs for wordpress / nginx / WPML install

I have some wordpress experience, but it's my first time using Nginx.我有一些 wordpress 的经验,但这是我第一次使用 Nginx。 I have a WordPress installation running on Nginx.我有一个 WordPress 安装在 Nginx 上运行。 I added WPML (multi-language plugin) https://wpml.org/我添加了 WPML(多语言插件) https://wpml.org/

The current URL structure is https://www.maindomain.com/blog/es/... .当前的URL结构为https://www.maindomain.com/blog/es/...。 & https://www.maindomain.com/blog/en/... . & 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/... .我正在寻找一种方法来重写 ninginx conf 中的 URL,以便整个设置可以使用: https://www.maindomain/es/blog/...。 instead of https://www.maindomain.com/blog/es/ and so on.而不是https://www.maindomain.com/blog/es/等等。

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.这在两个 URL 上都会出现 404 错误。

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 .您可以将 WordPress 安装在根目录而不是子目录 ( /blog ) 中,或者将域指向子目录 This will give you URLs like maindomain.com这将为您提供诸如maindomain.com类的 URL

You can then set the Language URL setting in WPML to "Different languages in directories".然后,您可以将 WPML 中的语言 URL 设置设置为“目录中的不同语言”。 This will give you URLs like maindomain.com/es/ .这将为您提供诸如maindomain.com/es/类的 URL。 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 .最后,您可以使用 WordPress 中的blog slug 创建一个页面(您应该能够为翻译设置相同的 slug),并且可以在maindomain.com/blogmaindomain.com/es/blog访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM