Question about rewrite

Hello,

I moved one site from apache to nginx, and I must say… Im very
satisfied.
Wont get into details about that now, just to say - thanks on the cool
project.

Anyway, to get to the point.
Im running mostly mobile site, so… I don’t wanna pc desktop users
browsing around, instead… I want to redirect those users to another
site.

I did a little reasearch about that, and… the only option of how I can
match those users is the “Profile/MIDP” part of UserAgent string. 99 %
of wap browsers send that, and other 1% sends variations on that, like
opera: J2ME/MIDP.
So I think thats the best deal.

I created rules like this:

   if ($http_user_agent !~* Profile/MIDP) {
           rewrite   ^/   http://www.anothersite.com/;
   }

However, that aint working right. So obviously im doing something wrong.
Can someone help me how I can properly match that string ?

On Saturday 05 April 2008 04:00:10 Sasa Ugrenovic wrote:

I did a little reasearch about that, and… the only option of how I can
However, that aint working right. So obviously im doing something wrong.
Can someone help me how I can properly match that string ?

    if ($http_user_agent !~* "Profile/MIDP") {
            rewrite   ^/   http://www.anothersite.com/ last;
    }

http://wiki.codemongers.com/NginxHttpRewriteModule#rewrite

Hey,

Be aware that the orginal User Agent line looks something like this:
“SonyEricssonW800i/R1BC Browser/SEMC-Browser/4.2 Profile/MIDP-2.0
Configuration/CLDC-1.1”

Do

    if ($http_user_agent !~* "Profile/MIDP") {

this still stands ? I mean, Will it match the profile/midp ?

Kind Regards,
Sasa

On Sat, 5 Apr 2008 04:25:19 -0400

On Saturday 05 April 2008 04:40:26 Sasa Ugrenovic wrote:

this still stands ? I mean, Will it match the profile/midp ?

Yes, .profile/midp. to be exact. The quotes are probably optional in
this
case, the essential part was the “last” keyword in rewrite.

The last directive tells nginx to finish url rewriting and do the
location
matching again with the updated url. However, I just realized that you
are
redirecting to another host, so probably what you need is “redirect”
or “permanent.” That will just redirect the user with 302 or 301 code.
Sorry for the confusion.

Hi.
So “last” means “finish this time and repeat matching from the start”,
and
“break” means “finish rewrite”?
But I confused which situation we need “break”, if I just finish rewrite
rule— I maybe don’t need rewrite.
In my case, I need to redirect a “internal” location, so I must use
“last”
here?
( /openpath/file.ext ====> @realpath/cache_file.ext )

location ~^ /openpath/ {
rewrite /openpath/(\w+).(\w+) @realpath/cache_$1.$2
last;
}

location ~^ @realpath/ {
alias /realpath;
internal;
}

2008/4/5, Denis S. Filimonov [email protected]:

Ok.

Im off for the weekend, so I’ll test it on monday.
Thank you.

Kind Regards,
Sasa

On Sat, 5 Apr 2008 05:57:55 -0400

On Sunday 06 April 2008 12:52:54 bianbian wrote:

Hi.
So “last” means “finish this time and repeat matching from the start”, and
“break” means “finish rewrite”?
Yes, that’s correct.
You use “last” when you want the updated url to go through location
matching
process again, and “break” when you don’t.

location ~^ @realpath/ {
alias /realpath;
internal;
}
Yes, in this situation you need a “last”. However, I don’t think it’ll
work
with @ in the location, I think those are more like identifiers of
locations,
rather than actual locations to which you can append stuff. You can
use /realpath/, as long as it’s “internal” nobody will get there
directly. I
could be wrong, though.

Ok, thanks. That was helpful.

However, Im don’t fully understand the last directive.

last - completes processing of rewrite directives, after which

searches for corresponding URI and location

How will it effect if i have multiple rewrite rules ?
To be exact… i have a file, mobile-phones.conf which is included in
vhost nginx config, for my primary domain.
And it looks something like this:

if ($http_user_agent !~* “Profile/MIDP”) {

rewrite ^/ http://www.anotherhost.com/;

}

if ($http_user_agent !~* Windows\ CE) {

rewrite ^/ http://www.anotherhost.com/;

}

So on… around 10 rewrite rules.

Basicly… question is, do I use ‘last’ directive on all of those
rewrite rules, or just the last one in mobile-phones.conf list ?

Kind Regards,
Sasa

On Sat, 5 Apr 2008 04:50:56 -0400