Cách tạo file robots.txt hoàn hảo cho WordPress | Joomla | Drupal | Magento

robots.txt file văn bản đặc biệt được đặt trên thư mục gốc chứa website để chỉ định các quy tắc và hạn chế truy cập của các robot (còn gọi là web crawler, spider hoặc bot) của các công cụ tìm kiếm hoặc các robot trên Internet.

Tệp robots.txt được các công cụ tìm kiếm đọc trước khi bắt đầu quét và lập chỉ mục nội dung của trang web. Nó dùng để thông báo cho các robot biết những phần của trang web mà bạn muốn họ truy cập hoặc không truy cập.

Ví dụ, bạn có thể sử dụng tệp robots.txt để từ chối các robot truy cập vào các thư mục nhất định của trang web, hoặc cấu hình để chỉ cho phép truy cập vào một số phần cụ thể của trang web. Ngoài ra, tệp robots.txt cũng cung cấp thông tin về phạm vi index của các công cụ tìm kiếm và tần suất quét của chúng.

Cần lưu ý rằng tệp robots.txt chỉ là một yêu cầu và không phải là một biện pháp bảo mật như nhiều người hay nhầm lẫn.

Bạn cũng nên lưu ý có thể có các robot không tuân thủ tệp robots.txt mà vẫn cào toàn bộ data của website hoặc truy cập vào toàn bộ các file để thu thập hoặc đánh cắp thông tin website (Phần này liên quan tới chính, tà hay – robot của ai điều khiển nhằm mục đích gì…)

Robot nằm ở đâu?

Như đã nói phần đầu bài file robots.txt sẽ nằm ở thư mục gốc của website cụ thể sẽ như sau:

https://vutruso.com/robots.txt

File robots.txt mặc định sẽ không có trên website mà quản trị viên phải tạo để khai báo các rules cho các web crawler, spider hoặc bot biết

File robots.txt gồm những gì?

File robots.txt có 4 phần chính như sau:

  • User-agent – quy tắc cho robot tìm kiếm
  • Disalow – từ chối quyền truy cập
  • Allow – cho phép truy cập
  • Sitemap – URL đầy đủ của bản đồ XML

File robots.txt có yêu cầu như sau:

– Mã hóa UTF-8 không có chữ ký BOM
– Tập tin có thể được truy cập bởi robot
– Máy chủ đưa ra trạng thái 200
– Kích thước lên tới 500 KB
– Một tệp cho tên miền
– Tên “robots.txt” không có chữ in hoa và chữ Cyrillic
– Tác nhân người dùng có liên quan được chỉ định trong nhóm quy tắc
– Không có xung đột giữa các chỉ thị.

Sửa file robots.txt cho WordPress

Việc tạo file robots.txt và sửa đổi file robots.txt rất đơn giản, bạn có thể đăng nhập vào hosting hoặc đăng nhập vào tài khoản FTP của bạn, tiếp theo truy cập vào vị trí chứa mã nguồn chứa website WordPress và tạo mới 1 file với tên là: robots.txt là xong

Tiếp theo bạn mở file robots.txt lên và nhập vào các thông tin như đề xuất của chúng tôi dưới đây, đây là file robots.txt tối ưu cho WordPress , các mã nguồn khác hoặc code khác vui lòng tìm hiểu thêm thông tin để tạo file robots.txt

User-agent: *
Disallow: /cgi-bin
Disallow: /wp-admin
Disallow: /wp-includes
Disallow: /wp-content/cache
Disallow: /wp-content/plugins
Disallow: /wp-json/
Disallow: /wp-login.php
Disallow: /wp-register.php
Disallow: /xmlrpc.php
Disallow: /license.txt
Disallow: /readme.html
Disallow: /trackback/
Disallow: /comments/feed/
Disallow: /*?replytocom
Disallow: */rss
Disallow: /author/
Disallow: /?
Disallow: /*?
Disallow: /?s=
Disallow: *&s=
Disallow: /search
Disallow: /search/
Disallow: *?attachment_id=
Disallow: *utm=
Disallow: */embed
Disallow: /archive/
Disallow: /wp-cron.php
Disallow: /wp-load.php
Disallow: /wp-login.php* 
Disallow: /customize.php* 
Allow: /wp-admin/admin-ajax.php
Allow: /wp-includes/*.css
Allow: /wp-includes/*.js
Allow: /wp-content/plugins/*.css
Allow: /wp-content/plugins/*.js
Allow: /*.css
Allow: /*.js

# Googlebot
User-agent: Googlebot 
Disallow: /feed/
Disallow: /feed$
Disallow: /*/feed$
Disallow: /feed

Sitemap: https://vutruso.com/sitemap_index.xml

Dòng đầu tiên cho biết tài nguyên có sẵn cho tất cả rô-bốt tìm kiếm (trình thu thập thông tin).

Chỉ thị không cho phép tìm kiếm hoặc lập chỉ mục các thư mục và tệp đăng ký, nguồn cấp dữ liệu RSS, trang tác giả, trang tìm kiếm và tệp đính kèm… có chữ Disallow ở đầu sẽ chặn cào

Cho phép truy cập các file js, css trong thư mục chứa plugin, cho phép truy cập các file .js và css

Cuối cùng là địa chỉ của bản đồ XML (Nhớ thay tên vutruso.com thành website của bạn nhé)

Lưu ý nếu bạn cho phép truy cập vào phần lưu trữ tác gì thì có thể bỏ dòng: Disallow: /author/

Lưu trữ tác giả ví dụ: https://vutruso.com/author/vutruso/

Nếu website của bạn đăng ký Google News thì có thể khai báo thêm

# Googlebot-News
User-agent: Googlebot-News
Allow: /feed
Allow: /feed/

Robots.txt cho các website sử dụng WooCommerce

Nếu bạn sử dụng plugin WooCommerce thì nên thêm vào

Disallow: /cart/
Disallow: /checkout/
Disallow: /*add-to-cart=*
Disallow: /my-account/

Ngoài ra, nếu bạn không sử dụng mã nguồn mở mà sử dụng các CMS khác có thể tham khảo file robots.txt được đề xuất dưới đây.

File robots.txt cho OpenCart

User-agent: *
Disallow: /*route=account/
Disallow: /*route=affiliate/
Disallow: /*route=checkout/
Disallow: /*route=product/search
Disallow: /index.php?route=product/product*&manufacturer_id=
Disallow: /admin
Disallow: /catalog
Disallow: /system
Disallow: /*?sort=
Disallow: /*&sort=
Disallow: /*?order=
Disallow: /*&order=
Disallow: /*?limit=
Disallow: /*&limit=
Disallow: /*?filter_name=
Disallow: /*&filter_name=
Disallow: /*?filter_sub_category=
Disallow: /*&filter_sub_category=
Disallow: /*?filter_description=
Disallow: /*&filter_description=
Disallow: /*?tracking=
Disallow: /*&tracking=
Disallow: /*compare-products
Disallow: /*search
Disallow: /*cart
Disallow: /*checkout
Disallow: /*login
Disallow: /*logout
Disallow: /*vouchers
Disallow: /*wishlist
Disallow: /*my-account
Disallow: /*order-history
Disallow: /*newsletter
Disallow: /*return-add
Disallow: /*forgot-password
Disallow: /*downloads
Disallow: /*returns
Disallow: /*transactions
Disallow: /*create-account
Disallow: /*recurring
Disallow: /*address-book
Disallow: /*reward-points
Disallow: /*affiliate-forgot-password
Disallow: /*create-affiliate-account
Disallow: /*affiliate-login
Disallow: /*affiliates
Disallow: /*?filter_tag=
Disallow: /*brands
Disallow: /*specials
Disallow: /*simpleregister
Disallow: /*simplecheckout
Disallow: *utm=
Allow: /catalog/view/javascript/
Allow: /catalog/view/theme/*/
Sitemap: https://vutruso.com/sitemap_index.xml

File robots.txt cho Joomla

User-agent: *
Disallow: /administrator/
Disallow: /bin/
Disallow: /cache/
Disallow: /cli/
Disallow: /components/
Disallow: /includes/
Disallow: /installation/
Disallow: /language/
Disallow: /layouts/
Disallow: /libraries/
Disallow: /logs/
Disallow: /modules/
Disallow: /plugins/
Disallow: /tmp/
Sitemap: https://vutruso.com/sitemap_index.xml

File robots.txt cho Drupal

User-agent: *
Allow: /core/*.css$
Allow: /core/*.css?
Allow: /core/*.js$
Allow: /core/*.js?
Allow: /core/*.gif
Allow: /core/*.jpg
Allow: /core/*.jpeg
Allow: /core/*.png
Allow: /core/*.svg
Allow: /profiles/*.css$
Allow: /profiles/*.css?
Allow: /profiles/*.js$
Allow: /profiles/*.js?
Allow: /profiles/*.gif
Allow: /profiles/*.jpg
Allow: /profiles/*.jpeg
Allow: /profiles/*.png
Allow: /profiles/*.svg
Disallow: /core/
Disallow: /profiles/
Disallow: /README.txt
Disallow: /web.config
Disallow: /admin/
Disallow: /comment/reply/
Disallow: /filter/tips/
Disallow: /node/add/
Disallow: /search/
Disallow: /user/register/
Disallow: /user/password/
Disallow: /user/login/
Disallow: /user/logout/
Disallow: /index.php/admin/
Disallow: /index.php/comment/reply/
Disallow: /index.php/filter/tips/
Disallow: /index.php/node/add/
Disallow: /index.php/search/
Disallow: /index.php/user/password/
Disallow: /index.php/user/register/
Disallow: /index.php/user/login/
Disallow: /index.php/user/logout/
Sitemap: https://vutruso.com/sitemap_index.xml

File robots.txt cho Magento

User-agent: *
Disallow: /index.php/
Disallow: /*?
Disallow: /checkout/
Disallow: /app/
Disallow: /lib/
Disallow: /*.php$
Disallow: /pkginfo/
Disallow: /report/
Disallow: /var/
Disallow: /catalog/
Disallow: /customer/
Disallow: /sendfriend/
Disallow: /review/
Disallow: /*SID=

File robots.txt cho MODX CMS

User-agent: *
Disallow: /*?id=
Disallow: /assets
Disallow: /assets/cache
Disallow: /assets/components
Disallow: /assets/docs
Disallow: /assets/export
Disallow: /assets/import
Disallow: /assets/modules
Disallow: /assets/plugins
Disallow: /assets/snippets
Disallow: /connectors
Disallow: /core
Disallow: /index.php
Disallow: /install
Disallow: /manager
Disallow: /profile
Disallow: /search

Hy vọng bài viết sẽ cung cấp 1 lượng thông tin cần thiết và giúp ích cho nhiều người, không có cái gì làm hoàn hảo cả nên mọi người hãy điều chỉnh sao cho phù hợp với website của mình nhé.

Mọi ý kiến thắc mắc vui lòng liên hệ qua email info@vutruso.com để được hỗ trợ./

Xin cảm ơn.

vutruso

Vũ Trụ Số chuyên cung cấp hosting cho WordPress, dịch vụ thiết kế website, quản trị website cho doanh nghiệp, dịch vụ quảng cáo Google, quảng cáo Facebook, các dịch vụ bảo mật website WordPress, tăng tốc website WordPress

Bài viết liên quan