请教一个nginx的rewrite规则
Jun 23, 2016 pm 01:48 PM 假设我用的泛解析域名为 *.domain.com
现在我要判断当域名不为www.domain.com并且满足条件为([\w]{2,5}).domain.com的二级域名进行重定向,将其定向到www.domain.com/domain.php?domain=([\w]{2,5})的rewrite规则。
首先我是这样写的:
set $domain '';if( $hots ~* ([\w]{2,5}).\domain\.com ){ set $domain $1; } if( $domain !~ "www" ){ rewrite ^$domain\.domain\.com(.*)$ http://www.domain.com$1?domain=$domain last;}
于是报错为\w为不安全的匹配。
然后我又改成:
set $domain '';if( $hots ~* “([\w]{2,5}).\domain\.com" ){ set $domain $1; } if( $domain != "www" ){ rewrite ^$domain\.domain\.com(.*)$ http://www.domain.com$1?domain=$domain&query_string redirect ;}
这次不报错了,但是却无法正确跳转。
所以请教一下这段代码问题出在哪,我应该如何改写?
回复讨论(解决方案)
于是报错为\w为不安全的匹配。
改写成[0-9a-zA-z]这样试试?
另外二级域名的解析也可以加在php的入口中,可以实现更灵活的功能
改成[0-9a-zA-z] 也是一样的,因之前他提示过\w的不安全后我就改成这样的,但是同样无效,后来加了双引号以后就没问题了,只是条件好像判断成不满足了

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to allow external network access to tomcat server

What are the nginx start and stop commands?

How to solve the problem of nginx when accessing the website

How to deploy nodejs project to server

How to communicate between docker containers
