Nginx Joomla国际化URL重写
我将Joomla与Nginx结合使用,目前我正在尝试为一个支持多种语言(意大利语、法语、汉语和德语)的网站实现URL重写 URL在域名后有国家代码,如下所示:Nginx Joomla国际化URL重写,joomla,url-rewriting,nginx,multilingual,Joomla,Url Rewriting,Nginx,Multilingual,我将Joomla与Nginx结合使用,目前我正在尝试为一个支持多种语言(意大利语、法语、汉语和德语)的网站实现URL重写 URL在域名后有国家代码,如下所示: http://www.example.com/fr/test/test.html 或 http://www.example.com/de/test/test.html 我希望重写URL,使国家代码成为子域的一部分: 所以 http://www.example.com/fr/test/test.html 变成 http://fr.examp
http://www.example.com/fr/test/test.html
或
http://www.example.com/de/test/test.html
我希望重写URL,使国家代码成为子域的一部分:所以
http://www.example.com/fr/test/test.html
变成
http://fr.example.com/test/test.html
有没有办法通过Nginx实现这一点,或者我应该为Joomla寻找第三方扩展(不是我最喜欢的选择)
谢谢
更新:我不够清楚:我希望重写URL的重定向是透明的。感谢VBart的帮助,以下是我的想法:
server {
server_name ~^(?<lang>.+)\.example\.com$;
location / {
rewrite /(.*)$ /$lang/$1 break;
proxy_pass http://www.example.com;
proxy_redirect http://www.example.com http://$lang.example.com/$request_uri;
}
}
服务器{
服务器名称~^(?.+)\.example\.com$;
位置/{
重写/(.*)$/$lang/$1中断;
代理通行证http://www.example.com;
代理服务器重定向http://www.example.com http://$lang.example.com/$request\u uri;
}
}
现在,Nginx有没有办法动态修改服务内容中的链接?ie:我希望生成页面中的所有链接看起来像http://fr...
而不是http://.../fr/...
?服务器{
server {
server_name ~^(?<lang>.+)\.example\.com$;
...
}
server {
server_name www.example.com;
rewrite ^/(?<lang>[a-z]+)(?<rest>.+)$ http://$lang.example.com$rest? permanent;
}
服务器名称~^(?.+)\.example\.com$;
...
}
服务器{
服务器名称www.example.com;
重写^/(?[a-z]+)(?。+)$http://$lang.example.com$rest?permanent;
}
相反的例子:
server {
server_name ~^(?<lang>.+)\.example\.com$;
return 301 http://www.example.com/$lang$request_uri;
}
server {
server_name www.example.com;
...
}
服务器{
服务器名称~^(?.+)\.example\.com$;
返回301http://www.example.com/$lang$request_uri;
}
服务器{
服务器名称www.example.com;
...
}
您好,谢谢您的帮助,但这似乎与我想要的正好相反。让我解释一下:当我输入http://fr.example.com/test/test.html
,在URL栏中,我希望我的Nginx显示页面http://www.example.com/fr/test/test.html
。使用您的解决方案,当我键入http://www.example.com/fr/test/test.html
,我被重定向到http://fr.example.com/test/test.html
,它不存在。我必须为每种语言创建一个新的服务器声明吗?顺便问一下,(?)
代表什么?它是否将括号捕获的所有内容分配给变量$lang
?是否将括号捕获的所有内容分配给变量$lang?对(请参见manpcresyntax
)好的,我添加了相反的示例。这是你想要的吗?从表面上看,它似乎做了我想要的,但当我尝试它时它不起作用。我还有一个重写指令:location/{try_files$uri$uri//index.php?q=$uri&$args;}
可能是冲突的那个?