定制 hryvinskyi/magento2-seo-robots-pack 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hryvinskyi/magento2-seo-robots-pack

Composer 安装命令:

composer require hryvinskyi/magento2-seo-robots-pack

包简介

Complete SEO Robots solution for Magento 2 with flexible directive management, multiselect UI, and independent X-Robots-Tag configuration

README 文档

README

Complete SEO robots meta tag and X-Robots-Tag HTTP header management for Magento 2 with flexible directive management and comprehensive Google robots directive support.

Overview

This metapackage provides a complete solution for managing robots meta tags and X-Robots-Tag HTTP headers in Magento 2. Version 2.0 introduces flexible directive management, supporting all Google robots directives with independent configuration for meta tags and HTTP headers.

Included Packages

Core Modules

  • hryvinskyi/magento2-seo-robots-api (v2.0.0) - API interfaces and contracts
  • hryvinskyi/magento2-seo-robots (v2.0.0) - Core robots functionality with validation and migration
  • hryvinskyi/magento2-seo-robots-admin-ui (v2.0.0) - Enhanced admin UI with multiselect directives
  • hryvinskyi/magento2-seo-robots-frontend (v2.0.0) - Frontend application with independent X-Robots-Tag support

Key Features

Flexible Directive Management

  • No limitations - Combine any robots directives freely (not limited to 8 predefined options like v1.x)
  • Multiselect UI - Hold Ctrl/Cmd to select multiple directives in admin
  • Comprehensive validation - Automatically detects conflicting directives (e.g., index + noindex)
  • Pattern-based rules - Configure directives per URL pattern with priority system

Demo

configuration_settings.gif

Supported Robots Directives

Basic Directives (Select Multiple)

  • index / noindex - Control page indexing
  • follow / nofollow - Control link following
  • noarchive - Prevent cached copy
  • nosnippet - Prevent snippet display in search results
  • notranslate - Prevent translation offers
  • noimageindex - Prevent image indexing
  • none - Equivalent to noindex,nofollow
  • all - Equivalent to index,follow (default)
  • max-snippet:[number] - Maximum snippet length (-1 for no limit)
  • max-image-preview:[none|standard|large] - Maximum image preview size
  • max-video-preview:[seconds] - Maximum video preview duration (-1 for no limit)
  • unavailable_after:[date] - Content removal date (RFC 850 format)

X-Robots-Tag Configuration

  • Configure X-Robots-Tag HTTP header separately from meta robots tag
  • Set different directives for HTTP header vs HTML meta tag
  • Automatic fallback to meta robots if no independent configuration

URL Pattern-Based Control

  • Define robots directives per URL pattern (e.g., */product/*, catalog_product_view)
  • Priority-based matching (highest priority wins)
  • Supports wildcards and full action names

HTTPS & Pagination Support

  • Separate directive configuration for HTTPS pages
  • Automatic robots directives for paginated content (?p= parameter)
  • Special handling for 404 pages (automatic NOINDEX,NOFOLLOW)

Installation

composer require hryvinskyi/magento2-seo-robots-pack:^2.0
php bin/magento module:enable Hryvinskyi_SeoRobotsApi Hryvinskyi_SeoRobots Hryvinskyi_SeoRobotsAdminUi Hryvinskyi_SeoRobotsFrontend
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Configuration

Navigate to Stores > Configuration > Hryvinskyi SEO > Meta Robots

Basic Configuration

  1. Enabled: Set to "Yes" to enable robots management
  2. Robots Meta Header Rules: Configure pattern-based rules
    • Priority: Higher priority rules match first
    • URL Pattern: Use wildcards (e.g., */customer/*) or action names (e.g., catalog_category_view)
    • Meta Robots Directives: Select multiple directives (hold Ctrl/Cmd)
    • X-Robots-Tag Directives: Optionally configure independent directives for HTTP header
  3. X-Robots-Tag Rules (Independent): Separate rules for X-Robots-Tag header only
  4. Robots Directives for HTTPS Pages: Multiselect directives for HTTPS
  5. Set NOINDEX,NOFOLLOW for 404 page: Automatically apply to error pages
  6. Paginated Content: Configure robots for pages with ?p= parameter
  7. Enable X-Robots-Tag Header: Enable/disable HTTP header

Configuration Examples

Example 1: Noindex Product Pages

  • Pattern: catalog_product_view
  • Meta Directives: noindex, follow
  • Result: <meta name="robots" content="NOINDEX,FOLLOW">

Example 2: X-Robots-Tag

  • Pattern: cms_page_view
  • X-Robots Directives: index, follow
  • Result:
    • HTTP Header: X-Robots-Tag: INDEX,FOLLOW

Example 3: Customer Account Protection

  • Pattern: */customer/account/*
  • Meta Directives: noindex, nofollow, noarchive
  • Result: Full protection from search engines

Migration from v1.x

Automatic Migration

Version 2.0 includes automatic migration via Setup Patch:

\Hryvinskyi\SeoRobots\Setup\Patch\Data\MigrateRobotsConfiguration

What Gets Migrated:

  • Old code-based configurations (1-8) automatically convert to directive arrays:
    • Code 1 (NOINDEX_NOFOLLOW) → ['noindex', 'nofollow']
    • Code 4 (INDEX_FOLLOW) → ['index', 'follow']
    • etc.
  • https_meta_robots setting
  • paginated_robots_type setting
  • All URL patterns and priorities preserved

No Manual Steps Required - Simply run setup:upgrade

Breaking Changes

  1. API Changes: RobotsListInterface::getMetaRobotsByCode() deprecated (still works)
  2. Return Types: getHttpsMetaRobots() and getPaginatedMetaRobots() now return arrays instead of integers
  3. Configuration Format: Stored as directive arrays instead of integer codes

API Usage

Building Robots String from Directives

use Hryvinskyi\SeoRobotsApi\Api\RobotsListInterface;

class YourClass
{
    private $robotsList;

    public function __construct(RobotsListInterface $robotsList)
    {
        $this->robotsList = $robotsList;
    }

    public function example()
    {
        // Build robots string from directive array
        $directives = ['noindex', 'follow', 'noarchive'];
        $robotsString = $this->robotsList->buildMetaRobotsFromDirectives($directives);
        // Result: "NOINDEX,FOLLOW,NOARCHIVE"
    }
}

Validating Directives

// Validate directive array for conflicts
$directives = ['index', 'noindex']; // Conflicting!
$validation = $this->robotsList->validateDirectives($directives);

if (!$validation['valid']) {
    foreach ($validation['errors'] as $error) {
        // Handle error: "Conflicting directives: index and noindex cannot be used together"
    }
}

Getting Available Directives

// Get all basic directives
$basicDirectives = $this->robotsList->getBasicDirectives();
// Returns: ['index', 'noindex', 'follow', 'nofollow', 'noarchive', ...]

// Get advanced directives
$advancedDirectives = $this->robotsList->getAdvancedDirectives();
// Returns: ['max-snippet', 'max-image-preview', ...]

Extension Points

Custom Robots Providers

Implement RobotsProviderInterface to provide custom robots logic:

namespace Vendor\Module\Model;

use Hryvinskyi\SeoRobotsFrontend\Model\RobotsProviderInterface;
use Magento\Framework\App\RequestInterface as HttpRequestInterface;

class CustomRobotsProvider implements RobotsProviderInterface
{
    public function getRobots(HttpRequestInterface $request): ?string
    {
        // Your custom logic
        if ($request->getParam('custom_param')) {
            return 'NOINDEX,FOLLOW';
        }
        return null;
    }

    public function getSortOrder(): int
    {
        return 100; // Execution order
    }
}

Register in di.xml:

<type name="Hryvinskyi\SeoRobotsFrontend\Model\ApplyRobots">
    <arguments>
        <argument name="robotsProviders" xsi:type="array">
            <item name="custom" xsi:type="object">Vendor\Module\Model\CustomRobotsProvider</item>
        </argument>
    </arguments>
</type>

Requirements

  • PHP 8.1, 8.2, or 8.3
  • Magento 2.4.x
  • Composer

Troubleshooting

Configuration Not Applying

  1. Clear Magento cache: php bin/magento cache:flush
  2. Verify module is enabled: php bin/magento module:status
  3. Check pattern matching - use action names instead of URL paths
  4. Verify priority - higher priority rules override lower ones

Migration Issues

If automatic migration fails:

  1. Backup your configuration: app/etc/config.php
  2. Manually convert using the code-to-directive mapping in CHANGELOG.md
  3. Report issue at: https://github.com/hryvinskyi/magento2-seo-robots-pack/issues

Directive Conflicts

Valid combinations:

  • ✅ noindex, follow
  • ✅ index, nofollow, noarchive
  • ❌ index, noindex (conflicting)
  • ❌ follow, nofollow (conflicting)

Support

Author

Volodymyr Hryvinskyi

License

MIT License - see LICENSE file for details

Changelog

See CHANGELOG.md for detailed version history.

hryvinskyi/magento2-seo-robots-pack 适用场景与选型建议

hryvinskyi/magento2-seo-robots-pack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 667 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hryvinskyi/magento2-seo-robots-pack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hryvinskyi/magento2-seo-robots-pack 我们能提供哪些服务?
定制开发 / 二次开发

基于 hryvinskyi/magento2-seo-robots-pack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 667
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-26