2010-03-29 191 views
3
rewrite ^/index\.asp /index.php last; 
rewrite ^/index\.asp\?boardid=([0-9]+)$ /forum-$1-1.html last; 
rewrite ^/index\.asp\?boardid=([0-9]+)(.*)$ /forum-$1-1.html last; 
rewrite ^/index_([0-9]+)(.*)$ /forum-$1-1.html last; 
rewrite ^/dispbbs\.asp\?boardID=([0-9]+)&ID=([0-9]+)$ /thread-$2-1-1.html last; 

我已经尝试了上面的重写规则,并得到一个死的结果,不工作。 我参考了很多文章和文章,并没有帮助。nginx重写规则不起作用?

有什么错误吗?

V/R, 加文


感谢您的答复。 :)

我已经改变了我的nginx的配置于

rewrite ^/index\.asp$ /index.php last; 
rewrite ^/index\.asp\?boardid=([0-9]+)(.*)$ /forum-$1-1.html last; 
rewrite ^/index\.asp\?boardid=([0-9]+)$ /forum-$1-1.html last; 
rewrite ^/dispbbs\.asp\?boardID=([0-9]+)&ID=([0-9]+)$ /thread-$2-1-1.html last; 

仍然没有工作。但我在规则中找不到任何错误。

回答

2

您不能在重写规则中匹配参数,它们可能只包含路径。原因很简单:假设参数可能有另一个命令;假设可能有其他参数没有考虑到(例如来自Google的关键字)。

所以你的规则应该以一种匹配路径的方式重写,然后检查参数。像这样:

rewrite ^/index_([0-9]+)(.*)$ /forum-$1-1.html last; 

location /index.asp { 
    if ($arg_boardid ~ "^([0-9]+)") { 
    rewrite^/forum-$1-1.html break; 
    } 
    rewrite^/index.php break; 
} 

location /dispbbs.asp { 
    rewrite^/thread-$arg_ID-1-1.html break; 
} 
+0

谢谢。但是,我在nginx.config中也有像rewrite ^/dispbbs_([0-9]+)_([0-9]+)\.html$ /thread-$2-1-1.html last;这样的规则,它们工作得很完美。我会尝试你的分段。 :) – WisdomFusion 2010-03-29 08:27:07

+0

rewrite ^/dispbbs_([0-9]+)_([0-9]+)\.html$ /thread-$2-1-1.html last; WisdomFusion 2010-03-29 08:56:46

+0

参数(查询字符串)后问问字符。之前您可以匹配任何内容,因为它是一个字符串,但不能对查询字符串进行匹配。 – 2010-03-29 09:31:39