How could I permanently redirect dynamic url with querystrings?

Hi, all

I recently migrates my web server from lighty to nginx(nginx/0.7.67 +
php-fpm), but there is something strange with the nginx rewrite rule.

The problem is, I wanna direct rules like this,

http://www1.example.com/dispbbs.asp?boardID=15&ID=164752

to a new domain(www2) and new format as follows,

http://www2.example.com/thread-164752-1-1.html

However, I gets some strange results,

http://www2.example.com/thread-164752-1-1.html?boardID=15&ID=164752

Why? Why does the querystring ‘?boardID=15&ID=164752’ still
appears and so strange?

Here is my settings in nginx.conf

...

#rewrite dynamic url with querystrings
if ($args ~* "boardid=[0-9]+&id=([0-9]+)") {
  set $tid $1;
  rewrite ^.*$ http://www2.example.com/thread-$tid-1-1.html permanent;
}
...
#here, i put some rewrite rules#
...
#at the end, rewrite undefined urls permanently
rewrite ^(.*) http://www2.example.com$1 permanent;
...

V/R,
gavin

Posted at Nginx Forum:

On 19.06.2010 16:53, WisdomFusion wrote:

#rewrite dynamic url with querystrings
if ($args ~* “boardid=[0-9]+&id=([0-9]+)”) {
set $tid $1;
rewrite ^.*$ http://www2.example.com/thread-$tid-1-1.html permanent;

#at the end, rewrite undefined urls permanently
rewrite ^(.*) http://www2.example.com$1 permanent;

  • rewrite ^ http://www2.example.com$request_uri? permanent;


Best regards,
Gena

Gena M. Wrote:

http://www2.example.com/thread-$tid-1-1.html
permanent;
nginx Info Page
Thanks. ^^

It works perfect. Thanks a lot.

By the way, I always refers to configuration from
Module ngx_http_rewrite_module, but it’s so brief that
some details like this problem I encountered are not included. Where
could I find more detailed reference materials?

V/R,
gavin

Posted at Nginx Forum:

On 20.06.2010 14:06, WisdomFusion wrote:

  • rewrite ^ http://www2.example.com$request_uri? permanent;

Thanks. ^^

It works perfect. Thanks a lot.

By the way, I always refers to configuration from
Module ngx_http_rewrite_module, but it’s so brief that
some details like this problem I encountered are not included. Where
could I find more detailed reference materials?

high quality English documentation can be located
at official nginx site: nginx documentation

information about “question mark as the last character”
present at http://wiki.nginx.org/NginxHttpRewriteModule:

If in the line of replacement arguments are indicated, then the rest of
the request arguments are appended to them. To avoid having them
appended, place a question mark as the last character:

rewrite ^/users/(.*)$ /show?user=$1? last;

‘^’ character is pcre regexp, it means ‘start of string’,
more detailed manual about Perl Compatible Regular Expressions
syntax is perlre - Perl regular expressions - Perldoc Browser
or http://www.pcre.org/pcre.txt

$request_uri - internal nginx variable,
it described at Module ngx_http_core_module

P.S.

quite often English documentation at http://wiki.nginx.org/
are more detailed than russian nginx: документация
(wiki describes many undocumented nginx options and features)

but Russian documentation at nginx: документация
always more accurate and correct than information at wiki,
because Russian documentation maintained in sync
with main development branch by creator of nginx.

it can be readed in english via Google Translate.


Best regards,
Gena

Gena M. Wrote:

permanent;
but it’s so brief that
http://wiki.nginx.org/NginxHttpRewriteModule:
‘^’ character is pcre regexp, it means 'start of
P.S.
always more accurate and correct than information


nginx mailing list
[email protected]
nginx Info Page

It’s very kind of you, both official site and wiki are good references.
Thanks for your paticient reply. :slight_smile:

Posted at Nginx Forum: