tags:

views:

330

answers:

2

Hi, all

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

A: 

Hi, Mark

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;
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;

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

WisdomFusion
A: 

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;
}
Alexander Azarov
Thanks. But, i also have rules like <code>rewrite ^/dispbbs_([0-9]+)_([0-9]+)\.html$ /thread-$2-1-1.html last;</code> in nginx.config, they work perfect. I'll try out your seggestions. :)
WisdomFusion
<code>rewrite ^/dispbbs_([0-9]+)_([0-9]+)\.html$ /thread-$2-1-1.html last;</code>
WisdomFusion
Arguments (query string) go after question character. You can match anything before, because it's a string, but you can not do matches against query string.
Alexander Azarov
Should read "because it's a path" instead of "because it's a string".
Alexander Azarov
Thanks for your patient. :) <code>rewrite ^/dv_rss\.asp(.*) /archiver/ last;</code>However, this one works perfect.
WisdomFusion
Please see http://en.wikipedia.org/wiki/URI_scheme for the explanation of URI parts (e.g. path and query)
Alexander Azarov
Thank you very much. I check the link out http://wiki.nginx.org/NginxHttpCoreModule#.24arg_PARAMETER, you are right. Url with querystring is not like string.
WisdomFusion
BTW, this site which only rewrites urls and redirects domain has no files in its root directory. So, do i have to add if condition to check the locations' existence? V/R, gavin
WisdomFusion
err, this rule works perfect: rewrite ^/index_([0-9]+)(.*)$ /forum-$1-1.html last; Thanks. :)
WisdomFusion