How to block Baiduspider: robots.txt and HTTP requests

Use robots.txt to ask Baidu's crawler to stop crawling, or an HTTP blocking rule to refuse matching requests. Choose the method for your goal, then verify it. A Baiduspider user agent alone does not prove a request came from Baidu.

Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)

At a glance

TypeSearch engine crawler
OperatorBaidu
PurposeWeb crawling for Baidu Search
Version2.0
robots.txt tokenBaiduspider
How to verifyReverse DNS hostname ends in .baidu.com or .baidu.jp and resolves back to the same IP; Baidu publishes no IP list.

Allow or block it in robots.txt

Block Baiduspider from the whole site

User-agent: Baiduspider
Disallow: /

Allow it again

User-agent: Baiduspider
Allow: /

How to block Baiduspider with robots.txt

Add the Baiduspider rule above to your site's root robots.txt, for example https://example.com/robots.txt. Merge it with existing rules rather than replacing rules for other crawlers. Disallow: / asks Baiduspider to stop crawling the whole site.

To block only a directory, use a path such as /private/ instead. These rules apply to Baiduspider, rather than every search engine. Blocking crawling can prevent Baidu from refreshing your content; it does not guarantee that an already known URL disappears from search results.

User-agent: Baiduspider
Disallow: /private/

How to refuse Baiduspider requests with Cloudflare

For a hostname whose traffic is proxied through Cloudflare, go to Security rules, choose Create rule > Custom rules and enter the expression below. Replace example.com with the hostname you want to protect; add a separate host condition if you also need www. Choose Block to refuse matching HTTP requests, rather than only asking a crawler not to fetch them.

Check the hostname and matching scope before deploying the rule. User agents can be spoofed: this matches a reported name, not verified Baidu identity. Use authentication to protect private content.

(http.host eq "example.com" and lower(http.user_agent) contains "baiduspider")

Test the HTTP block and compare a normal request

After replacing example.com with your hostname, run both commands below and check Cloudflare Security Events for the matching rule. With the Block action, the matching request should be refused; the default block status is 403. The comparison request should retain the behavior intended for ordinary visitors.

A 403 alone is not proof that this rule matched: other security rules can also deny a request. Changing the test UA exercises the matching condition; it does not impersonate or verify a real Baidu crawler.

curl -I -A "Baiduspider" https://example.com/
curl -I -A "UA-rule-check/1.0" https://example.com/

Check robots.txt and verify the request source

Open your public robots.txt and confirm that the expected text is served successfully. Then review server access logs for subsequent requests. Robots rules are instructions for cooperative crawlers, not an access-control mechanism; use authentication for private content.

A user agent containing Baiduspider can be spoofed. For a request you need to verify, check its reverse DNS hostname and resolve that hostname back to the original IP. A matching user agent alone does not prove the request came from Baidu.

String breakdown

FragmentMeaning
Mozilla/5.0Historical compatibility token. Nearly every browser claims "Mozilla/5.0" so that old servers do not serve it broken pages.
compatibleCompatibility token — historically sent by IE, now mostly by bots.
Baiduspider/2.0Baiduspider 2.0 — an automated crawler/bot, not a real browser.
+http://www.baidu.com/search/spider.htmlInfo page the bot operator publishes for webmasters.

Use it in code

curl

curl -A "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" https://example.com

Python (requests)

import requests
requests.get("https://example.com", headers={"User-Agent": "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"})

Playwright (Node.js)

const context = await browser.newContext({ userAgent: "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)" });

Source: 轻松两步,教你快速识别百度蜘蛛(User-Agent) · Baidu: robots.txt and blocking Baiduspider · Cloudflare: create a custom rule · Cloudflare: Rules language functions · RFC 9309: Robots Exclusion Protocol · checked September 2026

Related user agents

All user agent strings →

What does your own browser send? Check your user agent →