Welcome! Log In Create A New Profile

Advanced

How could I permanently redirect dynamic url with querystrings?

Posted by WisdomFusion 
How could I permanently redirect dynamic url with querystrings?
June 19, 2010 09:53AM
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
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;

- rewrite ^.*$ http://www2.example.com/thread-$tid-1-1.html permanent;
+ 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$1 permanent;
+ rewrite ^ http://www2.example.com$request_uri? permanent;

--
Best regards,
Gena

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Re: How could I permanently redirect dynamic url with querystrings?
June 20, 2010 07:06AM
Gena Makhomed Wrote:
-------------------------------------------------------
> 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;
>
> - rewrite ^.*$
> http://www2.example.com/thread-$tid-1-1.html
> permanent;
> + 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$1
> permanent;
> + rewrite ^ http://www2.example.com$request_uri?
> permanent;
>
> --
> Best regards,
> Gena
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx

Thanks. ^^

It works perfect. Thanks a lot.

By the way, I always refers to configuration from http://wiki.nginx.org/NginxHttpRewriteModule, 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
On 20.06.2010 14:06, WisdomFusion wrote:

>> - rewrite ^.*$ http://www2.example.com/thread-$tid-1-1.html permanent;
>> + rewrite ^ http://www2.example.com/thread-$tid-1-1.html? permanent;

>> - rewrite ^(.*) http://www2.example.com$1 permanent;
>> + rewrite ^ http://www2.example.com$request_uri? permanent;

> Thanks. ^^
>
> It works perfect. Thanks a lot.
>
> By the way, I always refers to configuration from
> http://wiki.nginx.org/NginxHttpRewriteModule, 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: http://nginx.org/en/docs/

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 http://perldoc.perl.org/perlre.html
or http://www.pcre.org/pcre.txt

$request_uri - internal nginx variable,
it described at http://wiki.nginx.org/NginxHttpCoreModule

P.S.

quite often English documentation at http://wiki.nginx.org/
are more detailed than russian http://sysoev.ru/nginx/docs/
(wiki describes many undocumented nginx options and features)

but Russian documentation at http://sysoev.ru/nginx/docs/
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

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Re: How could I permanently redirect dynamic url with querystrings?
June 21, 2010 09:58PM
Gena Makhomed Wrote:
-------------------------------------------------------
> On 20.06.2010 14:06, WisdomFusion wrote:
>
> >> - rewrite ^.*$
> http://www2.example.com/thread-$tid-1-1.html
> permanent;
> >> + rewrite ^
> http://www2.example.com/thread-$tid-1-1.html?
> permanent;
>
> >> - rewrite ^(.*) http://www2.example.com$1
> permanent;
> >> + rewrite ^
> http://www2.example.com$request_uri? permanent;
>
> > Thanks. ^^
> >
> > It works perfect. Thanks a lot.
> >
> > By the way, I always refers to configuration
> from
> > http://wiki.nginx.org/NginxHttpRewriteModule,
> 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: http://nginx.org/en/docs/
>
> 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 http://perldoc.perl.org/perlre.html
> or http://www.pcre.org/pcre.txt
>
> $request_uri - internal nginx variable,
> it described at
> http://wiki.nginx.org/NginxHttpCoreModule
>
> P.S.
>
> quite often English documentation at
> http://wiki.nginx.org/
> are more detailed than russian
> http://sysoev.ru/nginx/docs/
> (wiki describes many undocumented nginx options
> and features)
>
> but Russian documentation at
> http://sysoev.ru/nginx/docs/
> 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
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx


It's very kind of you, both official site and wiki are good references.
Thanks for your paticient reply. :)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 78
Record Number of Users: 10 on August 27, 2010
Record Number of Guests: 177 on August 21, 2010
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by MySQL