Robots.txt Basics for Beginners
Control which parts of a website search engines can crawl.
What robots.txt does
robots.txt is a plain text file at the root of a site (https://example.com/robots.txt) that tells search-engine crawlers which paths they may or may not crawl. It is a request, not a lock: well-behaved bots follow it, bad bots ignore it, and anyone can read the file.
/admin-backup/ there actually advertises it. Protect private areas with passwords/server rules.Syntax with a real example
User-agent: * Disallow: /admin/ Disallow: /search/ Disallow: /cart/ Allow: / Sitemap: https://example.com/sitemap.xml
| Line | Meaning |
|---|---|
User-agent: * | Rules for all crawlers (or name one, e.g. Googlebot) |
Disallow: /admin/ | Do not crawl URLs starting with /admin/ |
Allow: / | Everything else may be crawled |
Sitemap: | Full URL of your sitemap (see sitemaps) |
* and $ in paths | Wildcard and end-of-URL, e.g. Disallow: /*?sort=, Disallow: /*.pdf$ |
Disallow is not noindex
Blocking a URL in robots.txt stops crawling, but Google can still index the bare URL if other sites link to it (shown without a description). To keep a page out of search results, allow crawling and add <meta name="robots" content="noindex"> to the page (or an X-Robots-Tag: noindex header). Never block a page in robots.txt that you want Google to see the noindex on.
Costly mistakes
| Mistake | Result |
|---|---|
Disallow: / left from a staging site | The whole site disappears from Google over time |
Blocking /assets/ or CSS/JS files | Google cannot render pages properly; mobile-friendliness suffers |
| Blocking pages that have noindex | Google never sees the noindex |
Typos: Disalow, missing slash | Rule ignored |
| robots.txt returning 5xx errors | Google may pause crawling the site |
Test before and after changes
- Open
yourdomain.com/robots.txtin a browser – it must load as plain text with status 200. - Google Search Console → Settings → robots.txt report shows the version Google fetched and any errors.
- Use URL Inspection on an important page to confirm “Crawl allowed: Yes”.
- Python users can test rules with
urllib.robotparser– see our web scraping lesson.
robots.txt क्या करता है
robots.txt site के root (https://example.com/robots.txt) पर रखी सादी text file है जो search-engine crawlers को बताती है कि कौन से paths crawl कर सकते हैं या नहीं। यह अनुरोध है, ताला नहीं: अच्छे bots मानते हैं, बुरे bots नज़रअंदाज़ करते हैं, और कोई भी file पढ़ सकता है।
/admin-backup/ लिखना असल में उसका प्रचार करता है। निजी हिस्सों को passwords/server rules से बचाएँ।असली उदाहरण के साथ syntax
User-agent: * Disallow: /admin/ Disallow: /search/ Disallow: /cart/ Allow: / Sitemap: https://example.com/sitemap.xml
| Line | अर्थ |
|---|---|
User-agent: * | सभी crawlers के लिए नियम (या किसी एक का नाम, जैसे Googlebot) |
Disallow: /admin/ | /admin/ से शुरू होने वाले URLs crawl न करें |
Allow: / | बाक़ी सब crawl हो सकता है |
Sitemap: | आपके sitemap का पूरा URL (sitemaps देखें) |
Paths में * और $ | Wildcard और URL का अंत, जैसे Disallow: /*?sort=, Disallow: /*.pdf$ |
Disallow, noindex नहीं है
robots.txt में URL block करने से crawling रुकती है, पर दूसरी sites link करें तो Google बिना description के URL index कर सकता है। Page को search results से बाहर रखने के लिए crawling allow करें और page में <meta name="robots" content="noindex"> (या X-Robots-Tag: noindex header) लगाएँ। जिस page का noindex Google को दिखाना है उसे robots.txt में block न करें।
महँगी ग़लतियाँ
| ग़लती | नतीजा |
|---|---|
Staging site से बचा Disallow: / | समय के साथ पूरी site Google से गायब |
/assets/ या CSS/JS files block करना | Google pages ठीक से render नहीं कर पाता; mobile-friendliness पर असर |
| noindex वाले pages block करना | Google को noindex दिखता ही नहीं |
Typos: Disalow, slash छूटा | नियम नज़रअंदाज़ |
| robots.txt का 5xx errors देना | Google site की crawling रोक सकता है |
बदलाव से पहले और बाद जाँचें
- Browser में
yourdomain.com/robots.txtखोलें – status 200 के साथ सादे text में load होनी चाहिए। - Google Search Console → Settings → robots.txt report Google का लाया version और errors दिखाता है।
- किसी ज़रूरी page पर URL Inspection से “Crawl allowed: Yes” पक्का करें।
- Python users
urllib.robotparserसे नियम test कर सकते हैं – हमारा web scraping lesson देखें।
Frequently Asked Questions
Does robots.txt remove a page from Google?
No. It only stops crawling. To remove a page from results use a noindex meta tag (and allow crawling), delete it with a 404/410, or use Search Console’s Removals tool for urgent temporary removal.
Where should robots.txt be placed?
In the root of the host: https://example.com/robots.txt. A file in a sub-folder is ignored. Each subdomain needs its own file.
Should I block CSS and JavaScript?
No. Google needs them to render and understand your pages. Block only private or useless crawl paths such as admin, cart and internal search.
