0
0
Nginxdevops~5 mins

Rewrite directive in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the rewrite directive in nginx?
The rewrite directive changes the requested URL before nginx processes it further. It helps redirect or modify URLs based on patterns.
Click to reveal answer
beginner
How do you write a basic rewrite rule to redirect /old to /new?
Use rewrite ^/old$ /new permanent; to redirect requests from /old to /new with a permanent redirect.
Click to reveal answer
intermediate
What does the last flag do in a rewrite rule?
The last flag stops processing current rewrite rules and restarts location search with the new rewritten URL.
Click to reveal answer
intermediate
Explain the difference between permanent and redirect flags in rewrite.
permanent sends a 301 status (permanent redirect), while redirect sends a 302 status (temporary redirect).
Click to reveal answer
intermediate
What happens if you omit flags in a rewrite directive?
If no flag is given, nginx uses last by default, rewriting the URL and restarting location search.
Click to reveal answer
Which flag in the nginx rewrite directive causes a permanent redirect?
Abreak
Blast
Cpermanent
Dredirect
What does the rewrite ^/old$ /new last; directive do?
ARedirects /old to /new with a 302 temporary redirect
BReturns a 404 error for /old
CStops processing rewrite rules without redirect
DRedirects /old to /new and restarts location search
If you want to temporarily redirect a URL in nginx, which flag should you use?
Apermanent
Bredirect
Clast
Dbreak
What is the default behavior if no flag is specified in a rewrite directive?
AIt uses the last flag
BIt uses the break flag
CIt uses the redirect flag
DIt causes an error
Which directive is used to modify URLs before nginx processes them?
Arewrite
Bproxy_pass
Creturn
Dinclude
Describe how the nginx rewrite directive works and when you would use it.
Think about changing URLs before nginx serves content.
You got /4 concepts.
    Explain the difference between the 'last' and 'break' flags in nginx rewrite rules.
    Consider how nginx continues or stops processing after rewriting.
    You got /3 concepts.