我正在结合使用Joomla和Nginx,目前我正在尝试为一个支持多个语言(意大利语、法语、中文和德语)的网站实现一些URL重写。
urls的域名后面有国家代码,如下所示:
http://www.example.com/fr/test/test.html
orhttp://www.example.com/de/test/test.html
我希望重写urls,以使国家代码成为子域的一部分:
sohttp://www.example.com/fr/test/test.html
becomeshttp://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;
}
} 现在,Nginx是否有办法在所提供的内容中动态地修改链接?ie:我想让生成页面中的所有链接看起来像http://fr...而不是http://.../fr/...?
发布于 2012-05-31 19:54:56
server {
server_name ~^(?<lang>.+)\.example\.com$;
...
}
server {
server_name www.example.com;
rewrite ^/(?<lang>[a-z]+)(?<rest>.+)$ 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;
...
}https://stackoverflow.com/questions/10832034
复制相似问题