nianzong 发表于 2011-12-20 09:48

rewrite参数:permanent、redirect、last、break


                                                                                                需求:<br>1. 将/guide/下面的除了guide.htm之外的所有文件跳转到/guide/index.php页面<br>2. <br>http://x5.51.com/download/download-fwb.htm 跳转到 http://x5.51.com/index.php?a=diypage&amp;name=fwb<br>http://x5.51.com/download/download-wb.htm 跳转到 http://x5.51.com/index.php?a=diypage&amp;name=wb<br><br>nginx中的配置<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>if ( $request_uri !~* ^(/guide/guide.htm)$){<br>rewrite ^/guide/(.*)$&nbsp;&nbsp; /guide/index.php last;&nbsp; #这里的last不能换成permanent,否则就卡在那里,奇怪。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>#if ( $request_uri ~* ^(/download/download-fwb.htm)$){<br>rewrite ^(/download/download-fwb.htm)$ /index.php?a=diypage&amp;name=fwb permanent;&nbsp;&nbsp; #这里的permanent换成last后无效。<br>#}<br>rewrite ^(/download/download-wb.htm)$ /index.php?a=diypage&amp;name=wb permanent;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location ~ \.php$ {<br>............省略<br><br><br><br><table><tbody><tr><td class="number"><code></code><br></td><td class="content"><code class="plain plain">* last 相当于Apache里的标记,表示完成&lt;a href="/tag/rewrite/" onclick="tagshow('rewrite');return false;"&gt;rewrite&lt;/a&gt;</code></td></tr></tbody></table><div class="line alt2"><table><tbody><tr><td class="number"><code>2</code></td><td class="content"><code class="plain plain">* break 终止匹配, 不再匹配后面的规则</code></td></tr></tbody></table></div><div class="line alt1"><table><tbody><tr><td class="number"><code>3</code></td><td class="content"><code class="plain plain">* redirect 返回302临时重定向 地址栏会显示跳转后的地址</code></td></tr></tbody></table></div><div class="line alt2"><table><tbody><tr><td class="number"><code>4</code></td><td class="content"><code class="plain plain">* permanent 返回301永久重定向 地址栏会显示跳转后的地址</code></td></tr></tbody></table></div><br><ul><li> last - completes processing of rewrite directives, after which searches for corresponding URI and location
</li><li> break - completes processing of rewrite directives
</li><li> redirect - returns temporary redirect with code 302; it is used if the substituting line begins with <code>http://</code>
</li><li> permanent - returns permanent redirect with code 301
</li></ul><br>http://wiki.nginx.org/HttpRewriteModule#rewrite<br><br>~ &nbsp;为区分大小写匹配; <br>!~为区分大小写不匹配;<br>
~* 为不区分大小写匹配;<br>!~为不区分大小写不匹配;<br>
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
页: [1]
查看完整版本: rewrite参数:permanent、redirect、last、break