Challenge - 5 Problems
Trailing Slash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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;
}Attempts:
2 left
💡 Hint
Look at the rewrite regex and replacement carefully.
✗ Incorrect
The rewrite rule removes the trailing slash by matching any path ending with a slash and redirecting to the same path without it.
❓ Configuration
intermediate2: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?Attempts:
2 left
💡 Hint
Focus on matching URLs without trailing slash and not containing a dot.
✗ Incorrect
Option B matches URLs that do not end with a slash and do not contain a dot (to exclude files), then adds a trailing slash with a permanent redirect.
❓ Troubleshoot
advanced2: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/?Attempts:
2 left
💡 Hint
Think about how location matching and rewrite interact.
✗ Incorrect
The rewrite removes the trailing slash, but the location block matches only URLs with trailing slash, so nginx redirects again, causing a loop.
✅ Best Practice
advanced2: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?
Attempts:
2 left
💡 Hint
Think about how nginx distinguishes directories and files.
✗ Incorrect
Separate location blocks allow precise control: directories get trailing slash, files do not, avoiding redirect loops and confusion.
🧠 Conceptual
expert2: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?Attempts:
2 left
💡 Hint
Look at the regex and the return statement carefully.
✗ Incorrect
The if condition matches URLs ending with a slash and redirects to the same URL without the slash by using $uri which excludes the trailing slash.