开发者

nginx rewrite rule not working?

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;

I have try out rewrite rules above, and get a dead result, not working. I have refer to many posts and articles, and no help.

Is there any mistakes?

V/R, gavin


Thanks for your reply. :)

I have altered my nginx config to,

rewrite ^/index\.asp$ /index.php last;
rewrite ^/index\.asp\?boardid=([0-9]+)(.*)$ /forum-$1-1.html last;
rew开发者_如何学Crite ^/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;

Still not working. But I find no mistake in the rules.


You cannot match arguments in rewrite rules, they may include paths only. The reasons are simple: suppose arguments may have another order; suppose there can be additional arguments you did not take into account (e.g. keywords from Google).

So your rules should be rewritten in a way to match path at the first and then check arguments. Like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜