Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
Guide 60 · SEO & Website Basics · Hindi + English

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.

Do not use robots.txt to hide private files – listing /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
LineMeaning
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 pathsWildcard 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

MistakeResult
Disallow: / left from a staging siteThe whole site disappears from Google over time
Blocking /assets/ or CSS/JS filesGoogle cannot render pages properly; mobile-friendliness suffers
Blocking pages that have noindexGoogle never sees the noindex
Typos: Disalow, missing slashRule ignored
robots.txt returning 5xx errorsGoogle may pause crawling the site

Test before and after changes

  • Open yourdomain.com/robots.txt in 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 पढ़ सकता है।

निजी files छिपाने के लिए robots.txt इस्तेमाल न करें – वहाँ /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.

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free