0
0
Nginxdevops~10 mins

Rewrite directive in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to rewrite all requests to /home.

Nginx
rewrite [1] /home;
Drag options to blanks, or click blank then click option'
A/$
B/home$
C/index.html
D^/.*$
Attempts:
3 left
💡 Hint
Common Mistakes
Using a pattern that does not start with ^ or end with $
Using a literal string instead of a regex pattern
2fill in blank
medium

Complete the code to redirect requests from /old to /new permanently.

Nginx
rewrite ^/old[1] /new permanent;
Drag options to blanks, or click blank then click option'
A$
B.*
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using .* which matches anything after /old
Forgetting the $ to anchor the pattern
3fill in blank
hard

Fix the error in the rewrite directive to capture the path after /blog/ and redirect to /news/.

Nginx
rewrite ^/blog/[1] /news/$1 permanent;
Drag options to blanks, or click blank then click option'
A[a-z]+
B(.*)
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using * or + without parentheses which does not create a capture group
Using character classes like [a-z]+ which limits matching
4fill in blank
hard

Fill both blanks to rewrite requests ending with .php to .html internally.

Nginx
rewrite [1] [2] last;
Drag options to blanks, or click blank then click option'
A^(.*)\.php$
B\1.html
C\1.php
D^(.*)\.html$
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping the dot in .php
Using wrong replacement string without capture group
5fill in blank
hard

Fill all three blanks to rewrite URLs with query parameters to a clean URL format.

Nginx
rewrite ^/product/[1]/details\?id=[2]$ /item/[3] last;
Drag options to blanks, or click blank then click option'
A([a-zA-Z0-9_-]+)
B([0-9]+)
C$2
D$1
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping the question mark in the pattern
Mixing up $1 and $2 in the replacement