0
0
NextJSframework~20 mins

Robots.txt configuration in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Robots.txt Mastery in Next.js
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the effect of this robots.txt configuration in Next.js?
Given this robots.txt content served in a Next.js app, what will search engines be allowed to crawl?
NextJS
User-agent: *
Disallow: /admin
Allow: /admin/public
Sitemap: https://example.com/sitemap.xml
ASearch engines can crawl all pages except those under /admin except /admin/public which is allowed.
BSearch engines cannot crawl any pages under /admin including /admin/public.
CSearch engines can crawl all pages including /admin and /admin/public.
DSearch engines are blocked from crawling the entire site.
Attempts:
2 left
💡 Hint
Remember that 'Allow' can override 'Disallow' for specific paths.
📝 Syntax
intermediate
2:00remaining
Which robots.txt snippet is syntactically correct for Next.js static export?
Choose the valid robots.txt content that Next.js can serve without syntax errors.
A
User-agent: *
Disallow: /private
Allow: /public
Sitemap https://example.com/sitemap.xml
Extra: value
B
User-agent *
Disallow /private
Allow /public
Sitemap https://example.com/sitemap.xml
C
User-agent: *
Disallow: /private
Allow: /public
Sitemap: https://example.com/sitemap.xml
D
User-agent: *
Disallow: /private
Allow: /public
Sitemap: https://example.com/sitemap.xml
User-agent: /bot
Attempts:
2 left
💡 Hint
Check for correct use of colons and standard directives.
🔧 Debug
advanced
2:00remaining
Why does this Next.js robots.txt not block /secret as intended?
This robots.txt is served but /secret is still indexed by search engines. What is the issue?
NextJS
User-agent: *
Disallow: secret
AThe 'User-agent' directive is incorrect and should be 'User-agent: *'.
BThe path 'secret' is missing a leading slash, so it doesn't match '/secret'.
CThe 'Disallow' directive should be 'Disallow: /secret/*' to block all subpaths.
DThe robots.txt file must be named 'robotsjs.txt' in Next.js.
Attempts:
2 left
💡 Hint
Paths in robots.txt must start with a slash to match URLs correctly.
🧠 Conceptual
advanced
2:00remaining
What is the purpose of including a Sitemap directive in robots.txt in Next.js?
Why should you add a Sitemap URL in your robots.txt file when deploying a Next.js site?
AIt helps search engines find and index all pages efficiently by pointing to the sitemap location.
BIt blocks search engines from crawling the sitemap file itself.
CIt automatically generates the sitemap for the Next.js site.
DIt prevents duplicate content issues by redirecting crawlers.
Attempts:
2 left
💡 Hint
Think about how search engines discover pages on your site.
state_output
expert
3:00remaining
What is the output behavior when Next.js serves this robots.txt file dynamically?
Consider a Next.js API route serving robots.txt with this code snippet: ```js export default function handler(req, res) { res.setHeader('Content-Type', 'text/plain'); res.write('User-agent: *\nDisallow: /private'); res.end(); } ``` What will a search engine see when requesting /robots.txt?
NextJS
export default function handler(req, res) {
  res.setHeader('Content-Type', 'text/plain');
  res.write('User-agent: *\nDisallow: /private');
  res.end();
}
AThe search engine receives an HTML page instead of robots.txt content.
BThe robots.txt content is served but with incorrect Content-Type causing it to be ignored.
CThe server returns a 404 Not Found error for /robots.txt.
DThe search engine receives a valid robots.txt blocking /private directory.
Attempts:
2 left
💡 Hint
Check the Content-Type header and response body.