简体   繁体   中英

what is the difference between break; and last; in nginx rewrite?

i am new in NGINX. moved from apache. in htaccess apapche it works fine.I already try some converter and didnt work well as on apache. some converter use break other use last.i try a lot hours. this is my htaccess. thanks

# 404 ERROR NOT FOUND PAGE
ErrorDocument 404 /404.php

# 301 REDIRECT add WWW
RewriteCond %{HTTP_HOST} ^website.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [r=301,nc]

# IP Canonicalization/ change IP to domain name
RewriteCond %{HTTP_HOST} ^111\.222\.333\.444
RewriteRule (.*) http://www.website.com/$1 [R=301,L]

# NO rewrite for exact file/folder name. ex: website.com/index.php and website.com/admin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# modul. ex: website.com/news and website.com/news/page/3
RewriteRule ^([^/]+)/?$ index.php?mod=$1 [QSA,L]
RewriteRule ^([^/]+)/page/([0-9]+)/?$ index.php?mod=$1&page=$2 [QSA,L]

#detail content. ex: website.com/news/123/title-news.html or website.com/news/123/title-news or website.com/news/123
RewriteRule ^([^/]+)/([0-9]+)/[^/]+\.html$ index.php?mod=$1&id=$2 [QSA,L]
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ index.php?mod=$1&id=$2 [QSA,L]
RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?mod=$1&id=$2 [QSA,L]

thanks so much.

From the official site: http://wiki.nginx.org/HttpRewriteModule#rewrite

difference between break; and last

last - completes processing of rewrite directives, after which searches for corresponding URI and location

break - completes processing of rewrite directives and breakes location lookup cycle by not doing any location lookup and internal jump at all

Module ngx_http_rewrite_module says:

last

stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI;

break

stops processing the current set of ngx_http_rewrite_module directives as with the break directive;

last is usual way and used with rewrites way often than break

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM