将域重定向到默认语言NGINX [英] Redirect domain to default language NGINX

查看:111
本文介绍了将域重定向到默认语言NGINX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过长达301年的奋斗,将site.com重定向到site.com/en并将site.com/my-page重定向到site.com/en/my-page

Been struggling for so long to 301 redirect site.com to site.com/en and site.com/my-page to site.com/en/my-page

我设法使第一个重定向起作用,但没有使第二个重定向起作用!也可能只使用一个规则吗?那么我的第二条规则怎么了?

I manage to make the first redirect work, but not the second! also is it possible to use only one rule for both? So what is wrong with my second rule?

rewrite "^/(?![a-z]{2}|[a-z]{2}-[a-z]{2})$" /en redirect;
rewrite "^/(?![a-z]{2}|[a-z]{2}-[a-z]{2})/(.*)$" /en/$2 redirect;

非常感谢.

推荐答案

我认为您可以从另一个角度通过定义相关位置来进行处理,例如:

I think you can approach it from the other angle, by defining relevant locations, e.g.:

location / {
    return 301 /en$request_uri;
}

location = /my-page {
    return 301 /en/my-page;
}

location /en/ {
   ...
}

这篇关于将域重定向到默认语言NGINX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆