robots.txt: What We Hide and Why
Most websites have a robots.txt full of Disallow rules, but every Disallow tells a crawler "something exists here." A better approach: disallow all, allow only public.
Allow-Whitelist Strategy
User-agent: *
Disallow: /
Allow: /$
Allow: /sk
Allow: /en
Allow: /blog
Allow: /authors
Allow: /storage/blog-images
Allow: /sitemap.xml
Allow: /llms.txt
Sitemap: https://example.com/sitemap.xml
The first rule Disallow: / blocks everything. Then Allow rules permit only what we want indexed.
Why Not Blacklist?
Blacklist approach:
Disallow: /mark
Disallow: /debug
Disallow: /storage/uploads
Disallow: /login
Problem: every Disallow tells a crawler "the path /mark exists." Hackers read robots.txt, it's the first reconnaissance step.
Whitelist approach:
Disallow: /
Allow: /blog
The crawler sees only what we want. /mark, /debug, /uploads: never mentioned.
What We Allow
| Path | Why |
|---|---|
/ + /sk + /en | Homepages |
/blog | Articles + index |
/authors | Author profiles |
/storage/blog-images | Cover images |
/sitemap.xml | Sitemap |
/llms.txt | LLM-friendly overview |
What We Never Mention
/mark: admin panel (protected by auth + RBAC)/debug: debug panel (protected by APP_DEBUG)/storage/uploads: user uploads/login,/register: auth pages/mark/*: all admin routes
These paths are protected differently: auth middleware, noindex meta tags, APP_DEBUG gating. robots.txt is not a security boundary, just a crawl hint.
Implementation
#[Route(path: '/robots.txt', method: 'GET', name: 'robots')]
final class RobotsAction
{
public function handle(Request $request): Response
{
$content = 'User-agent: *' . "\n"
. 'Disallow: /' . "\n"
. 'Allow: /$' . "\n"
. 'Allow: /sk' . "\n"
. 'Allow: /en' . "\n"
. 'Allow: /blog' . "\n"
. 'Allow: /authors' . "\n"
. 'Allow: /storage/blog-images' . "\n"
. 'Allow: /sitemap.xml' . "\n"
. 'Allow: /llms.txt' . "\n"
. "\n"
. 'Sitemap: ' . $request->absoluteUrl('/sitemap.xml') . "\n";
$response = new Response($content);
$response->setHeader('Content-Type', 'text/plain; charset=utf-8');
return $response;
}
}
$request->absoluteUrl('/sitemap.xml'): absolute URL for the Sitemap line.
Common Mistakes
- Blacklist instead of whitelist: reveals admin page existence
- Missing Sitemap line: Google must find the sitemap elsewhere
- Allow: /storage/uploads: user uploads should not be indexed
- Disallow: /blog: blocks article indexing
The fix is one file with twenty lines. We replaced the blacklist with a whitelist, added the Sitemap line, and closed the admin gap. Google re-crawled within hours.
robots.txt remains a simple text file, just not one you should ignore. When you know what to hide, the Allow list writes itself. The next person who deploys your app should not have to guess which paths are public.
→ How we built the sitemap: dynamic XML sitemap with hreflang → JSON-LD structured data: rich results for blog articles → CSP & htmx interaction: when security meets the frontend
Comments (0)
No comments yet — be the first to react.