0
0
Nginxdevops~20 mins

Trailing slash normalization in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Trailing Slash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this nginx rewrite rule?
Given the nginx configuration snippet below, what will be the final URL after a client requests http://example.com/path/?
Nginx
location /path/ {
    rewrite ^/(.*)/$ /$1 permanent;
}
ARedirects to http://example.com/path (without trailing slash)
BRedirects to http://example.com/path/ (no change)
CReturns 404 Not Found
DRedirects to http://example.com//path (double slash)
Attempts:
2 left
💡 Hint
Look at the rewrite regex and replacement carefully.
Configuration
intermediate
2:00remaining
Choose the correct nginx config to add trailing slash if missing
Which nginx configuration snippet will redirect http://example.com/path to http://example.com/path/ (adding trailing slash) using a 301 redirect?
Arewrite ^/(.*)$ /$1/ permanent;
Brewrite ^([^.]*[^/])$ $1/ permanent;
Crewrite ^/(.*)/$ /$1 permanent;
Drewrite ^([^.]*[^/])$ /$1 permanent;
Attempts:
2 left
💡 Hint
Focus on matching URLs without trailing slash and not containing a dot.
Troubleshoot
advanced
2:00remaining
Why does this trailing slash removal rule cause a redirect loop?
Consider this nginx config:
location /app/ {
    rewrite ^/(.*)/$ /$1 permanent;
    proxy_pass http://backend/;
}
Why might this cause a redirect loop when accessing /app/?
ABecause the rewrite removes the slash but the location requires it, causing repeated redirects
BBecause proxy_pass is missing a trailing slash, causing wrong backend path
CBecause permanent redirects are cached and never updated
DBecause the regex does not match the URL path
Attempts:
2 left
💡 Hint
Think about how location matching and rewrite interact.
Best Practice
advanced
2:00remaining
Which approach is best for consistent trailing slash handling in nginx?
You want all URLs to have no trailing slash except for directories which must have it. Which nginx config approach is best?
AUse proxy_pass without any rewrite rules and handle trailing slashes in backend
BUse a single rewrite rule to remove all trailing slashes unconditionally
CUse separate location blocks for directories and files with rewrite rules to add or remove slashes accordingly
DUse rewrite rules to add trailing slashes to all URLs regardless of type
Attempts:
2 left
💡 Hint
Think about how nginx distinguishes directories and files.
🧠 Conceptual
expert
2:00remaining
What is the effect of this nginx config on URL normalization?
Analyze this nginx snippet:
if ($request_uri ~* ".+/$") {
    return 301 $scheme://$host$uri;
}
What does it do?
ARedirects URLs without a trailing slash to add one
BDoes nothing because $uri is undefined
CBlocks access to URLs ending with a slash
DRedirects URLs ending with a slash to the same URL without the slash
Attempts:
2 left
💡 Hint
Look at the regex and the return statement carefully.