0
0
Nginxdevops~10 mins

Conditional redirects with if 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 redirect all HTTP requests to HTTPS.

Nginx
if ($scheme = [1]) {
    return 301 https://$host$request_uri;
}
Drag options to blanks, or click blank then click option'
Ahttps
Bhttp
Cftp
Dws
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'https' in the condition causes a redirect loop.
Using unsupported schemes like 'ftp' or 'ws'.
2fill in blank
medium

Complete the code to redirect users from example.com to www.example.com.

Nginx
if ($host = [1]) {
    return 301 https://www.example.com$request_uri;
}
Drag options to blanks, or click blank then click option'
Aexample.com
Bwww.example.com
Cexample.net
Dwww.example.net
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'www.example.com' instead of 'example.com'.
Using a different domain like 'example.net'.
3fill in blank
hard

Fix the error in the code to redirect mobile users to m.example.com.

Nginx
if ($http_user_agent ~* [1]) {
    return 302 https://m.example.com$request_uri;
}
Drag options to blanks, or click blank then click option'
A"Mobile"
B/Mobile/
CMobile
D/mobile/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding quotes or slashes around the regex pattern.
Using case-sensitive match (~ instead of ~*).
4fill in blank
hard

Fill both blanks to redirect requests with query parameter 'ref=old' to '/newpage'.

Nginx
if ($arg_[1] = [2]) {
    return 301 /newpage;
}
Drag options to blanks, or click blank then click option'
Aref
Bold
Cnew
Dpage
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names.
Checking for wrong values like 'new' instead of 'old'.
5fill in blank
hard

Fill all three blanks to redirect requests from 'example.org' with user agent containing 'Bot' to '/botpage'.

Nginx
if ($host = [1]) {
    if ($http_user_agent ~* [2]) {
        return 302 [3];
    }
}
Drag options to blanks, or click blank then click option'
Aexample.org
BBot
C/botpage
D/userpage
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the host or user agent values.
Using wrong redirect URLs.