Beginners के लिए Robots.txt Basics
Website के कौन से parts search engines crawl कर सकते हैं, इसे control करें.
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 देखें।
अक्सर पूछे जाने वाले सवाल
क्या robots.txt page को Google से हटाता है?
नहीं। यह सिर्फ़ crawling रोकता है। Results से हटाने के लिए noindex meta tag (crawling allow करके), 404/410 से delete, या तुरंत अस्थायी हटाने के लिए Search Console का Removals tool।
robots.txt कहाँ रखनी चाहिए?
Host के root में: https://example.com/robots.txt। Sub-folder की file नज़रअंदाज़ होती है। हर subdomain की अपनी file चाहिए।
क्या CSS और JavaScript block करूँ?
नहीं। Google को pages render और समझने के लिए इनकी ज़रूरत है। सिर्फ़ admin, cart और internal search जैसे निजी या बेकार crawl paths block करें।
