<div>Hi.</div>
<div>So &quot;last&quot; means &quot;finish this time and repeat matching from the start&quot;, and &quot;break&quot; means &quot;finish rewrite&quot;?</div>
<div>But I confused&nbsp;which situation&nbsp;we need &quot;break&quot;, if I just finish rewrite rule--- I maybe don&#39;t need rewrite.<br>In my case, I need to redirect a &quot;internal&quot; location, so I must use &quot;last&quot; here?</div>

<div>( /openpath/file.ext &nbsp;====&gt;&nbsp; @realpath/cache_file.ext )</div>
<div>&nbsp;</div>
<div>&nbsp; location ~^ /openpath/ {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewrite&nbsp;&nbsp; /openpath/(\w+)\.(\w+)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @realpath/cache_$1.$2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last;</div>
<div>&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp; location ~^ @realpath/ {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alias&nbsp;&nbsp;&nbsp; /realpath;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; internal;</div>
<div>&nbsp; }</div>
<div>&nbsp;</div>
<div><span class="gmail_quote">2008/4/5, Denis S. Filimonov &lt;<a href="mailto:den.lists@gmail.com">den.lists@gmail.com</a>&gt;:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">The last directive tells nginx to finish url rewriting and do the location<br>matching again with the updated url. However, I just realized that you are<br>
redirecting to another host, so probably what you need is &quot;redirect&quot;<br>or &quot;permanent.&quot; That will just redirect the user with 302 or 301 code.<br>Sorry for the confusion.<br><br>On Saturday 05 April 2008 05:43:38 Sasa Ugrenovic wrote:<br>
&gt; Ok, thanks. That was helpful.<br>&gt;<br>&gt; However, Im don&#39;t fully understand the last directive.<br>&gt;<br>&gt; # last - completes processing of rewrite directives, after which searches<br>&gt; for corresponding URI and location<br>
&gt;<br>&gt; How will it effect if i have multiple rewrite rules ?<br>&gt; To be exact.. i have a file, mobile-phones.conf which is included in vhost<br>&gt; nginx config, for my primary domain. And it looks something like this:<br>
&gt;<br>&gt; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($http_user_agent !~* &quot;Profile/MIDP&quot;) {<br>&gt; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewrite&nbsp;&nbsp; ^/&nbsp;&nbsp; <a href="http://www.anotherhost.com/">http://www.anotherhost.com/</a>;<br>&gt; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($http_user_agent !~* Windows\ CE) {<br>
&gt; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewrite&nbsp;&nbsp;^/&nbsp;&nbsp; <a href="http://www.anotherhost.com/">http://www.anotherhost.com/</a>;<br>&gt; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt; So on.. around 10 rewrite rules.<br>&gt;<br>&gt; Basicly... question is, do I use &#39;last&#39; directive on all of those rewrite<br>
&gt; rules, or just the last one in mobile-phones.conf list ?<br>&gt;<br>&gt; Kind Regards,<br>&gt; Sasa<br>&gt;<br>&gt; On Sat, 5 Apr 2008 04:50:56 -0400<br>&gt;<br>&gt; &quot;Denis S. Filimonov&quot; &lt;<a href="mailto:den.lists@gmail.com">den.lists@gmail.com</a>&gt; wrote:<br>
&gt; &gt; On Saturday 05 April 2008 04:40:26 Sasa Ugrenovic wrote:<br>&gt; &gt; &gt; Hey,<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Be aware that the orginal User Agent line looks something like this:<br>&gt; &gt; &gt; &quot;SonyEricssonW800i/R1BC Browser/SEMC-Browser/4.2 Profile/MIDP-2.0<br>
&gt; &gt; &gt; Configuration/CLDC-1.1&quot;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Do<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($http_user_agent !~* &quot;Profile/MIDP&quot;) {<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; this still stands ? I mean, Will it match the *profile/midp* ?<br>
&gt; &gt;<br>&gt; &gt; Yes, .*profile/midp.* to be exact. The quotes are probably optional in<br>&gt; &gt; this case, the essential part was the &quot;last&quot; keyword in rewrite.<br>&gt; &gt;<br>&gt; &gt; &gt; Kind Regards,<br>
&gt; &gt; &gt; Sasa<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On Sat, 5 Apr 2008 04:25:19 -0400<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &quot;Denis S. Filimonov&quot; &lt;<a href="mailto:den.lists@gmail.com">den.lists@gmail.com</a>&gt; wrote:<br>
&gt; &gt; &gt; &gt; On Saturday 05 April 2008 04:00:10 Sasa Ugrenovic wrote:<br>&gt; &gt; &gt; &gt; &gt; Hello,<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; I moved one site from apache to nginx, and I must say... Im very<br>
&gt; &gt; &gt; &gt; &gt; satisfied. Wont get into details about that now, just to say -<br>&gt; &gt; &gt; &gt; &gt; thanks on the cool project.<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; Anyway, to get to the point.<br>
&gt; &gt; &gt; &gt; &gt; Im running mostly mobile site, so.. I don&#39;t wanna pc desktop users<br>&gt; &gt; &gt; &gt; &gt; browsing around, instead.. I want to redirect those users to<br>&gt; &gt; &gt; &gt; &gt; another site.<br>
&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; I did a little reasearch about that, and... the only option of how<br>&gt; &gt; &gt; &gt; &gt; I can match those users is the &quot;Profile/MIDP&quot; part of UserAgent<br>
&gt; &gt; &gt; &gt; &gt; string. 99 % of wap browsers send that, and other 1% sends<br>&gt; &gt; &gt; &gt; &gt; variations on that, like opera: J2ME/MIDP. So I think thats the<br>&gt; &gt; &gt; &gt; &gt; best deal.<br>&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; I created rules like this:<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($http_user_agent !~* Profile/MIDP) {<br>&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite&nbsp;&nbsp; ^/&nbsp;&nbsp; <a href="http://www.anothersite.com/">http://www.anothersite.com/</a>;<br>
&gt; &gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; However, that aint working right. So obviously im doing something<br>&gt; &gt; &gt; &gt; &gt; wrong. Can someone help me how I can properly match that string ?<br>
&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($http_user_agent !~* &quot;Profile/MIDP&quot;) {<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewrite&nbsp;&nbsp; ^/&nbsp;&nbsp; <a href="http://www.anothersite.com/">http://www.anothersite.com/</a> last;<br>
&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; <a href="http://wiki.codemongers.com/NginxHttpRewriteModule#rewrite">http://wiki.codemongers.com/NginxHttpRewriteModule#rewrite</a><br>&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; --<br>&gt; &gt; &gt; &gt; Denis.<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt; Denis.<br><br><br><br>--<br>Denis.<br><br></blockquote></div><br><br clear="all"><br>-- <br>bianbian coding life:<br><a href="http://bianbian.org">http://bianbian.org</a>