0
0
Nginxdevops~5 mins

Trailing slash normalization in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is trailing slash normalization in web servers?
Trailing slash normalization means making sure URLs either always end with a slash or never do, to keep URLs consistent and avoid duplicate content.
Click to reveal answer
beginner
Why normalize trailing slashes in URLs?
To improve SEO by avoiding duplicate content and to ensure consistent URL handling by the server and browsers.
Click to reveal answer
intermediate
How do you redirect URLs without trailing slash to ones with trailing slash in nginx?
Use a rewrite rule like:
rewrite ^([^.]*[^/])$ $1/ permanent;
This adds a slash at the end if missing.
Click to reveal answer
intermediate
What does the nginx directive try_files $uri $uri/ =404; do related to trailing slashes?
It tries to serve the exact URI first, then the URI with a trailing slash, and returns 404 if neither exists. Helps handle directories and files properly.
Click to reveal answer
intermediate
What is the difference between a 301 and 302 redirect in trailing slash normalization?
301 is a permanent redirect telling browsers and search engines the URL changed permanently. 302 is temporary. Use 301 for trailing slash normalization to keep SEO benefits.
Click to reveal answer
Which nginx directive is commonly used to add a trailing slash to URLs missing it?
Aroot /var/www/html;
Bproxy_pass http://backend;
Clisten 80;
Drewrite ^([^.]*[^/])$ $1/ permanent;
What status code should you use for permanent trailing slash redirects?
A200
B301
C302
D404
What does the following nginx config do?
try_files $uri $uri/ =404;
ABlocks all requests
BAlways redirects to homepage
CTries file, then directory, else 404
DEnables gzip compression
Why avoid having both /page and /page/ accessible on your site?
AIt causes duplicate content issues for SEO
BIt confuses users
CIt slows down the server
DIt breaks HTTPS
Which is true about trailing slash normalization?
AIt ensures consistent URL format
BIt only applies to image files
CIt disables caching
DIt requires changing DNS settings
Explain how to configure nginx to redirect URLs without trailing slashes to ones with trailing slashes.
Think about using rewrite with a regex and permanent flag.
You got /4 concepts.
    Describe why trailing slash normalization is important for websites and SEO.
    Consider how search engines treat URLs with and without slashes.
    You got /4 concepts.