PR SEO

ปรับปรุง SEO ด้วย robots.txt: เพิ่มประสิทธิภาพเว็บไซต์ผ่านการควบคุมครอว์เลอร์ที่ชาญฉลาดขึ้น

Published: 2025.01.08 Updated: 2026.03.12
เครือข่ายที่แผ่ขยายไปทั่วโลก

การควบคุมครอว์เลอร์ plays an important role in both SEO and webประสิทธิภาพเว็บไซต์. Search-engine ครอว์เลอร์ move through a เว็บไซต์ and collect information so they can retrieve the data needed to show pages in ผลการค้นหา. By controlling ครอว์เลอร์ behavior apPRoPRiately, you can ปรับปรุง SEO results and ประสิทธิภาพเว็บไซต์.

The central เครื่องมือ for this is robots.txt. This article explains robots.txt in depth, from พื้นฐาน to ใช้งานจริง ใช้, points of caution, and advanced techniques, so that you can become genuinely PRoficient with it.

The Complete SEO คู่มือ [2025 Edition]: The Full Map to อันดับการค้นหาที่สูงขึ้น
The Complete SEO คู่มือ [2025 Edition]: The Full Map to อันดับการค้นหาที่สูงขึ้น

บทที่ 1: พื้นฐานของ robots.txt

A network sPReading around the world

robots.txt คืออะไร? การควบคุมครอว์เลอร์ทำงานอย่างไร

robots.txt is a plain-text file placed in the root directory of a เว็บไซต์. It tells ครอว์เลอร์ which parts of the เว็บไซต์ they may crawl and which parts they should ไม่t crawl.

When a ครอว์เลอร์ accesses a เว็บไซต์, it usually reads robots.txt first and then crawls the เว็บไซต์ according to those instructions. robots.txt is a request to ครอว์เลอร์, ไม่t a forceful block, but major เสิร์ชเอนจิน do respect it. However, becaใช้ malicious ครอว์เลอร์ and some other bots may igไม่re robots.txt, you should never rely on it alone to PRotect confidential information.

ตำแหน่งที่วาง robots.txt รูปแบบไฟล์ และชุดอักขระ

robots.txt must be placed in the root directory of the เว็บไซต์, such as HTTPS://example.com/robots.txt.

It will ไม่t work if you place it in a subdirectory. The file name also has to be lowercase robots.txt.

The file format must be plain text, and UTF-8 encoding is strongly recommended. If you ใช้ aไม่ther encoding, ครอว์เลอร์ may fail to interPRet the file correctly.

ไวยากรณ์พื้นฐาน: User-agent, Disallow, Allow และรายละเอียดของกฎ

robots.txt is written with directives such as ผู้ใช้-agent, Disallow, and Allow. These directives are case-sensitive and are written one per line.

  • ผู้ใช้-agent:

    Specifies which ครอว์เลอร์ a rule applies to. You can name a specific ครอว์เลอร์ or ใช้ * for every ครอว์เลอร์. By declaring multiple ผู้ใช้-agent lines, you can define different rules for different ครอว์เลอร์. Examples:

    User-agent: Googlebot

    ,

    User-agent: Bingbot

    ,

    User-agent: *

    .

  • Disallow:

    Specifies a path that must ไม่t be crawled. It is written as a relative path beginning with a slash. An empty Disallow line means everything is allowed. Examples:

    Disallow: /private/

    ,

    Disallow:

    .

  • Allow:

    Specifies a path that may be crawled. It is ใช้d when you want to allow part of a location that has been blocked with Disallow. An Allow rule takes PRecedence over Disallow in that case. Example:

    Disallow: /private/

    and

    Allow: /private/public.html

    .

วิธีใช้ไวลด์การ์ด (*) และ ($): การจับคู่เส้นทางที่ยืดหยุ่นและการใช้งานขั้นสูง

The asterisk matches any character string. For example, Disallow: /*.pdf blocks every PDF file, and Disallow: /images/*.jpg$ blocks only JPG files under the /images/ directory.

The dollar sign matches the end of a line. For example, Disallow: /blog/$ blocks access to the /blog/ directory itself while still allowing addresses such as /blog/article1/.

การตั้งค่า Crawl-delay: ลดภาระเซิร์ฟเวอร์และผลกระทบต่อ Googlebot

With the Crawl-delay directive, you can specify the interval between ครอว์เลอร์ requests in seconds. This can help when โหลดเซิร์ฟเวอร์ is high, but Googlebot does ไม่t officially การสนับสนุน Crawl-delay. Google PReviously recommended crawl-rate settings in Search Console, but ไม่w handles this automatically, so it usually does ไม่t require much attention.

Becaใช้ Google has ปรับปรุงd its automatic crawl-rate adjustment, and in line with a broader effort to simplify the ประสบการณ์ผู้ใช้, Google is ending การสนับสนุน for the crawl rate limiter เครื่องมือ in Search Console.

Planned end of การสนับสนุน for the crawl-rate limiter เครื่องมือ in Search Console

It may still have an effect on other ครอว์เลอร์.

Specifying เว็บไซต์map: guiding ครอว์เลอร์ and handling multiple เว็บไซต์maps

You can specify เว็บไซต์map URLs with the เว็บไซต์map directive. This helps ครอว์เลอร์ ทำความเข้าใจ the structure of the เว็บไซต์ more easily and ปรับปรุงs crawl efficiency. You can also specify multiple เว็บไซต์maps. Examples: Sitemap: https://example.com/sitemap.xml and Sitemap: https://example.com/sitemap_images.xml.

Supercharge SEO: Build a Google-Friendly โครงสร้างเว็บไซต์ with เว็บไซต์map.xml

บทที่ 2: ใช้งานจริง robots.txt examples

A man typing on a laptop

PRotecting login-required pages: Disallow: /member/

เนื้อหา that requires login, such as members-only pages, should generally be excluded from search-engine indexing.

By using robots.txt, you can PRevent ครอว์เลอร์ from accessing these pages and reduce wasted การครอว์ล. For example, if members-only เนื้อหา is stored under /member/, writing Disallow: /member/ blocks access to every file and subdirectory under that location.

However, robots.txt is only a request to ครอว์เลอร์, so malicious ครอว์เลอร์ may igไม่re it.

Truly sensitive information must be PRotected with ฝั่งเซิร์ฟเวอร์ authentication rather than robots.txt. robots.txt should be treated as a การสนับสนุนing method for limiting ครอว์เลอร์ access and saving ทรัพยากรเซิร์ฟเวอร์. In many cases, it is apPRoPRiate to allow access to the login page itself so that ครอว์เลอร์ can ทำความเข้าใจ that authentication is required.

ควบคุม URL ที่มีพารามิเตอร์: Disallow: /*?page=*

Parameterized URLs can sometimes make the same เนื้อหา accessible under multiple URLs, which may be treated as duplicate เนื้อหา. For example, if you ใช้ a ?page= parameter for pagination, you may end up with pages like example.com/blog?page=1 and example.com/blog?page=2 that have different URLs but almost the same เนื้อหา.

By writing Disallow: /*?page=*, you can block access to every URL that includes the page= parameter. However, this can remove all paginated เนื้อหา from เสิร์ชเอนจิน and may hurt SEO.

A better apPRoach is to ใช้ a แท็ก caไม่nical and indicate the caไม่nical URL. If every paginated page points to the first page, such as example.com/blog, with a แท็ก caไม่nical, you can avoid duplicate-เนื้อหา issues and communicate the correct page to เสิร์ชเอนจิน.

Using robots.txt to control pagination should be treated as a last resort when implementing แท็ก caไม่nical is ไม่t possible.

Controlling a specific ครอว์เลอร์: ผู้ใช้-agent: YandexBot Disallow: /

With the ผู้ใช้-agent directive, you can set different rules for different ครอว์เลอร์. If you write User-agent: YandexBot and then Disallow: /, only YandexBot will be blocked from the entire เว็บไซต์. Other ครอว์เลอร์ will follow rules set under other ผู้ใช้-agent sections, or the rules under User-agent: *.

Typical cases where you may want to control a specific ครอว์เลอร์ include the following.

  • When a specific ครอว์เลอร์ is placing excessive load on the server

  • When a specific ครอว์เลอร์ is igไม่ring robots.txt and causing PRoblems

  • When you want to hide region-specific เนื้อหา from ครอว์เลอร์ of เสิร์ชเอนจิน that are ไม่t ใช้d in that region

In these and similar cases, the ผู้ใช้-agent directive is ใช้ful. The names of major search-engine ครอว์เลอร์ can be confirmed in each เสิร์ชเอนจิน’s official documentation.

บทที่ 3: Cautions and common mistakes in robots.txt

A man opeคะแนน a smartโทรศัพท์

robots.txt is a powerful เครื่องมือ, but incorrect settings can have serious consequences for a เว็บไซต์. This บทที่ explains common mistakes and points of caution so that you can ใช้ robots.txt safely and effectively.

3.1 ความเสียหายต่อ SEO จากความผิดพลาดใน robots.txt: หลุดจากผลการค้นหา

The most serious mistake in robots.txt is accidentally blocking important pages from การครอว์ล.

If you disallow PRoduct pages or service pages, for example, those pages may fall out of the search index and disappear from ผลการค้นหา. That directly reduces เว็บไซต์ ทราฟฟิก and can severely harm SEO.

Whenever you change robots.txt, always ใช้ the robots.txt testing เครื่องมือ in Google Search Console to confirm that only the intended pages are blocked. After the change, continue monitoring การจัดอันดับ and ทราฟฟิก regularly so you can catch any unintended effects.

3.2 ความผิดพลาดของการใช้ Allow กับหน้าที่ตั้งใจจะบล็อก

The Allow directive should be ใช้d only when you want to permit part of a location that has been blocked with Disallow. For example, if you want to block /PRivate/ but allow only /PRivate/public.HTML, you would ใช้ both Disallow: /private/ and Allow: /private/public.html.

Using Allow alone for an area that has ไม่t been disallowed has ไม่ effect. ครอว์เลอร์ generally assume every page is accessible unless it has been explicitly blocked with Disallow.

3.3 ความไวต่อการใช้ตัวพิมพ์ใหญ่-เล็ก: ต้องระวังเป็นพิเศษ

ผู้ใช้-agent, Disallow, Allow, and URL paths are all case-sensitive. For example, disallow: /images/ is treated differently from Disallow: /images/ and will ไม่t work as intended.

When writing robots.txt, always ใช้ the correct capitalization and check carefully for typographical errors.

3.4 Differences in ครอว์เลอร์ behavior: dealing with malicious ครอว์เลอร์

robots.txt ผลงาน with good-faith ครอว์เลอร์ such as Googlebot and Bingbot, but malicious ครอว์เลอร์ may igไม่re it completely. That means robots.txt alone canไม่t PRotect sensitive information.

Information that is truly confidential must be PRotected with ฝั่งเซิร์ฟเวอร์ authentication or access restrictions. You need to ทำความเข้าใจ that robots.txt is only a เครื่องมือ for controlling cooperative ครอว์เลอร์ and is ไม่t sufficient as a ความปลอดภัย measure.

3.5 robots.txt alone canไม่t PRovide ความปลอดภัย

As ไม่ted above, robots.txt is insufficient as a ความปลอดภัย measure. Anyone can read the เนื้อหาs of a robots.txt file, so malicious ผู้ใช้ may ใช้ it as a clue for ค้นหาing restricted areas.

Real ความปลอดภัย requires a layered apPRoach that combines multiple methods, including password PRotection, access control lists, and firewalls, ไม่t robots.txt alone.

3.6 พฤติกรรมที่ไม่คาดคิดจากการใช้ไวลด์การ์ดมากเกินไป

Wildcards such as * and $ make path matching more flexible, but overusing them can block pages you never meant to block. For example, Disallow: /*image* would block ไม่t only the /images/ directory but also a URL such as /article/my-image.jpg.

When using wildcards, check the full scope of their effect carefully and make sure you are ไม่t blocking pages unintentionally.

3.7 แคชของ robots.txt: ความล่าช้าก่อนที่การเปลี่ยนแปลงจะแสดงผล

เสิร์ชเอนจิน cache robots.txt, so changes are ไม่t always reflected immediately. Even if you check with a testing เครื่องมือ right after editing it, the result may still be based on the PRevious version.

In Google Search Console, you can request that robots.txt be fetched again through the robots.txt tester. This can shorten the delay before the cache updates and your changes are reflected.

By following these cautions and configuring robots.txt PRoperly, you can ปรับปรุง SEO and avoid unnecessary risk.

บทที่ 4: robots.txt creation เครื่องมือ and verification methods

A man typing

This บทที่ explains how to create, test, and revise robots.txt efficiently. By following these ขั้นตอน, you can PRevent unintended mistakes and maximize webประสิทธิภาพเว็บไซต์.

4.1 Using robots.txt creation เครื่องมือ

You can write robots.txt manually, but online เครื่องมือ let you do it faster and with fewer mistakes. These เครื่องมือ generate a robots.txt file automatically once you input the necessary directives, which helps reduce syntax errors and rule mistakes.

RePResentative เครื่องมือ include the following.

  • Google Search Console robots.txt tester:

    A built-in Search Console เครื่องมือ that can create, edit, and test robots.txt. If you already ใช้ Search Console, this is often the easiest choice.

  • SEO checker เครื่องมือ:

    Some SEO เครื่องมือ include robots.txt generation features. Becaใช้ they can be ใช้d together with other SEO functions, they are convenient when optimizing a เว็บไซต์ more broadly.

  • Other online robots.txt generators:

    If you search the web for robots.txt generator, you will ค้นหา many เครื่องมือฟรี. These are suiตาราง for creating a simple robots.txt file.

Which เครื่องมือ is best depends on your needs and the size of the เว็บไซต์.

4.2 การทดสอบ robots.txt ใน Google Search Console

Once you create robots.txt, you must test it to verify that ครอว์เลอร์ interPRet it correctly. Google Search Console PRovides a robots.txt testing เครื่องมือ that can show whether a specific URL is ครอว์ลได้ and whether there are mistakes in the file.

The testing PRocess is as follows.

  1. Open Google Search Console and select the PRoperty for the target เว็บไซต์.

  2. Choose the robots.txt tester from the menu on the left.

  3. Enter the URL you want to test and click the Test button.

  4. รีวิว whether the URL is ครอว์ลได้ and which directive is being applied.

Whenever you change robots.txt, ใช้ this เครื่องมือ and confirm that the file ผลงาน exactly as intended.

4.3 รีวิวing and fixing robots.txt

Becaใช้ robots.txt is placed in the root directory of a เว็บไซต์, you can open it directly in a browser, รีวิว its เนื้อหาs, and revise it if necessary. For example, accessing HTTPS://example.com/robots.txt will display the file.

When making corrections, open robots.txt in a text editor, make the necessary changes, and upload it to the server. Becaใช้ เสิร์ชเอนจิน need to refresh their cache, it may take a little time before the changes are reflected.

The robots.txt tester in Google Search Console lets you edit and test at the same time, making it easier to iterate on corrections and verification.

By following these ขั้นตอน, you can keep robots.txt in an optimal state and ปรับปรุง both SEO and ประสิทธิภาพเว็บไซต์.

บทที่ 5: การควบคุมครอว์เลอร์ beyond robots.txt

Differences from the meta robots tag and how to ใช้ each

The meta robots tag is ใช้d to control ครอว์เลอร์ on an individual page basis. When ใช้d together with robots.txt, it enables finer control. ไม่index instructs เสิร์ชเอนจิน ไม่t to index a page, and ไม่follow instructs them ไม่t to follow links. If you add ไม่index to a page that has also been blocked from การครอว์ล with robots.txt, it may help remove an already indexed page from ผลการค้นหา in some cases.

Using it together with ไม่index and ไม่follow

You can specify multiple directives separated by commas, such as ไม่index,follow.

Control through the X-Robots-Tag ส่วนหัว HTTP

By using X-Robots-Tag in the ส่วนหัวการตอบกลับ HTTP, you can control การครอว์ล for ไม่n-HTML files such as PDFs and images as well. This requires ฝั่งเซิร์ฟเวอร์ configuration.

สรุป

robots.txt is an indispensable เครื่องมือ for both SEO and webประสิทธิภาพเว็บไซต์.

When you ทำความเข้าใจ the points covered in this article and configure robots.txt PRoperly, you can draw out the full potential of your เว็บไซต์. It is important to stay current and keep optimizing robots.txt over time.

ภาคผนวก: ตัวอย่าง robots.txt รวมถึงแบบขั้นสูง

  • Allow only certain file types for a specific ครอว์เลอร์:

User-agent: Googlebot-Image Allow: /images/*.jpg Allow: /images/*.png Disallow: / User-agent: * Disallow: /images/

  • Slow down access for a specific ครอว์เลอร์:

User-agent: AhrefsBot Crawl-delay: 10 User-agent: * Allow: /

ใช้ these advanced patterns to optimize your เว็บไซต์ and move it toward success.