- 主题:求助一条nginx rewrite规则
ngnix新手,正则不熟,下面这个搞晕了。
目标:把 www.XXX.com/tags/BBB 重写为 www.XXX.com/tags/?tag=BBB&key=ZZZ
其中ZZZ和XXX是固定不变的, BBB是每次请求不同的tag
我写了个:
location /tags/ {
rewrite ^/tags/(.+)$ /tags/?tag=$1&key=ZZZ break;
}
发现好像重写后的又被匹配了,循环掉了,于是尝试:
location /tags/ {
rewrite ^/tags/(^[^\?]*)$ /tags/?tag=$1&key=ZZZ break;
}
但是还是没有用,还试了其他几种,太乱了,有点晕,搞不定了。我觉得第二种应该对啊,麻烦熟手给个提示,错误在哪里,应该怎么写? 谢谢啦!
--
FROM 122.246.42.*
用last会循环,用break,那么只有这个location之内的其它规则才会执行
也就是说,你需要在location /tags/ 里面做fastcgi_*(假设你用的是php)
location /tags/ {
rewrite ^/tags/(.*)$ /tags/t.php?tag=$1&AAA=BBB break;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
--
FROM 180.157.72.*
【 在 Orpherus 的大作中提到: 】
: 用last会循环,用break,那么只有这个location之内的其它规则才会执行
: 也就是说,你需要在location /tags/ 里面做fastcgi_*(假设你用的是php)
: location /tags/ {
: ...................
谢谢,慢慢研究中
--
FROM 122.246.42.*