2
我对nginx很新,现在我想用nginx从用户传递的URL中生成一个新的URL。如何使用查询字符串生成带有子域的URL到新URL?
实施例:
用户键入到像http://us.domain.com浏览器,我想nginx的生成http://www.domain.com/?portal=us或http://domain.com/?portal=us。
如何在nginx中使用rewrite来做到这一点?
我对nginx很新,现在我想用nginx从用户传递的URL中生成一个新的URL。如何使用查询字符串生成带有子域的URL到新URL?
实施例:
用户键入到像http://us.domain.com浏览器,我想nginx的生成http://www.domain.com/?portal=us或http://domain.com/?portal=us。
如何在nginx中使用rewrite来做到这一点?
你的意思是重定向,对吧?
http { # ... server { server_name us.domain.com; location/{ rewrite ^/ http://www.domain.com/?portal=us; } } }
东西没有那么快,但更普遍的:
server {
listen 80;
server_name domain.com;
if ($host ~* (.*)\.domain\.com) {
set $subdomain $1;
rewrite (.*) http://domain.com/?portal=$subdomain;
}