Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I don't understand the difference between break and last (flags of rewrite). The documentation is rather abstruse. I've tried to switch between the two in some of my configs, but I couldn't spot any difference in behavior. Can someone please explain these flags in more detail? Preferably with an example that shows different behavior when flipping one flag to another.

share|improve this question
    
I don't know the answer, but please update the wiki.nginx.org when you get your answer. Also, the English-language nginx mailing list is quite active, and Igor (the main developer) answers hundreds of questions per month, so perhaps ask there. –  rmalayter Apr 12 '10 at 2:21
    
@rmalayter - this question was asked on the nginx mailing list. Igor answered it but the answer didn't make much sense to me either: pubbs.net/nginx/200908/46047 –  user39883 Apr 12 '10 at 22:35
    
pubbs.net link is broken as the domain was taken over. Sorry, was not able to find where it should point. ;( –  Tino Aug 9 '12 at 13:01
add comment

2 Answers 2

up vote 11 down vote accepted

You may have different sets of rewrite rules for different locations. When rewrite module meets last, it stops processing the current set and the rewritten request is passed once again to find the appropriate location (and the new set of rewriting rules). If the rule ends with break, the rewriting also stops, but the rewritten request is not passed to another location.

That is, if there are two locations: loc1 and loc2, and there's a rewriting rule in loc1 that changes loc1 to loc2 AND ends with last, the request will be rewritten and passed to location loc2. If the rule ends with break, it will belong to location loc1.

share|improve this answer
    
You mean if the rewrite has the break flag it won't search for a matching location block, thus making it belong to location loc1. –  Martin Fjordvald Apr 15 '10 at 10:19
    
Exactly. Fixed. –  minaev Apr 15 '10 at 10:37
add comment

I still don't understand it really.

Is it like that?

# .html is rewritten to .htm and it is possible to rewrite it again
location ~ \.html {
 rewrite ^/([a-z0-9_]+)\.html$ /$1.htm last;
}
# .htm is rewritten to .php and because of "break" the rewriting stops completely
location ~ \.htm {
 rewrite ^/([a-z0-9_]+)\.htm$ /$1.php break;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.