0
0
Nginxdevops~20 mins

Rewrite flags (last, break, redirect, permanent) in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rewrite Flags Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What happens when using the 'last' rewrite flag?
Given this nginx rewrite rule:
rewrite ^/oldpath/(.*)$ /newpath/$1 last;

What is the effect of the 'last' flag in this context?
Nginx
rewrite ^/oldpath/(.*)$ /newpath/$1 last;
ASends a 301 permanent redirect to the client with the rewritten URI.
BStops processing current rewrite directives and restarts location search with the new URI.
CStops processing rewrite directives and serves the rewritten URI immediately without further processing.
DSends a 302 temporary redirect to the client with the rewritten URI.
Attempts:
2 left
💡 Hint
Think about how nginx handles URI rewriting and location matching after the rewrite.
💻 Command Output
intermediate
2:00remaining
What does the 'break' rewrite flag do in nginx?
Consider this rewrite rule:
rewrite ^/temp/(.*)$ /final/$1 break;

What is the behavior of the 'break' flag here?
Nginx
rewrite ^/temp/(.*)$ /final/$1 break;
ASends a 301 redirect to the client with the rewritten URI.
BRestarts location search with the rewritten URI.
CSends a 302 redirect to the client with the rewritten URI.
DStops processing rewrite directives and continues processing the request within the current location using the rewritten URI.
Attempts:
2 left
💡 Hint
Think about whether nginx changes location blocks after this rewrite.
💻 Command Output
advanced
2:00remaining
What is the HTTP response when using the 'redirect' rewrite flag?
Given this rewrite rule:
rewrite ^/old/(.*)$ /new/$1 redirect;

What HTTP status code does nginx send to the client?
Nginx
rewrite ^/old/(.*)$ /new/$1 redirect;
A302 Found (Temporary Redirect)
B301 Moved Permanently
C307 Temporary Redirect
D200 OK with rewritten URI internally
Attempts:
2 left
💡 Hint
The 'redirect' flag sends a temporary redirect status code.
💻 Command Output
advanced
2:00remaining
What HTTP status code does the 'permanent' rewrite flag send?
Analyze this rewrite rule:
rewrite ^/site/(.*)$ /website/$1 permanent;

What status code will nginx send to the client?
Nginx
rewrite ^/site/(.*)$ /website/$1 permanent;
A303 See Other
B302 Found
C301 Moved Permanently
D200 OK with internal rewrite
Attempts:
2 left
💡 Hint
The 'permanent' flag sends a permanent redirect status code.
Troubleshoot
expert
3:00remaining
Why does a rewrite with 'last' flag cause a redirect loop?
You have this nginx config snippet:
location /app/ {
  rewrite ^/app/(.*)$ /app/$1 last;
}

Requests to /app/page cause a redirect loop. What is the most likely reason?
Nginx
location /app/ {
  rewrite ^/app/(.*)$ /app/$1 last;
}
AThe rewrite rewrites the URI to the same URI, causing nginx to restart location search endlessly.
BThe 'last' flag is invalid here and causes nginx to crash.
CThe rewrite rule syntax is incorrect and nginx ignores it.
DThe 'break' flag should be used instead to avoid loops.
Attempts:
2 left
💡 Hint
Consider what happens when the rewritten URI matches the original location again.