nginx子域重写 [英] nginx subdomain rewrite

查看:53
本文介绍了nginx子域重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个nginx重写规则来重写:

I need a nginx rewrite rule to rewrite from:

http://some-keyword.example.comwww.example.com/keyword.php?keyword=$some-keyword

尽管前面没有www的域仍会重写为www.example.com,并且www不会作为关键字.

while domain without www in front still rewrites to www.example.com and www isn't taken as a keyword.

请您帮我解决这个问题,怎么写这两个规则?

Please could you help me to solve this problem, how to write these two rules?

推荐答案

如果您打算重定向,则:

If you meant redirect, then:

server {
  server_name ~^(.*)\.example\.com$ ;

  rewrite ^ http://www.example.com/keyword.php?keyword=$1 redirect;
}

如果是 rewrite ,则只需执行

server {
  server_name example.com ~^(.*)\.example\.com$ ;

  rewrite ^ /keyword.php?keyword=$1 break;

#  location /keyword.php {
#    ....
#  }
}

这篇关于nginx子域重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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