Redirect Management Module for 1C-Bitrix

Redirect Management Module for 1C-Bitrix After migrating a site to a new URL structure, Google Search Console often shows thousands of 404 errors. Old URLs like `/catalog/product-123.html` need to redirect to `/catalog/category/product-name/`. Writing 8,000 redirects in `.htaccess` is possible, b

Our competencies:

Frequently Asked Questions

Redirect Management Module for 1C-Bitrix

After migrating a site to a new URL structure, Google Search Console often shows thousands of 404 errors. Old URLs like /catalog/product-123.html need to redirect to /catalog/category/product-name/. Writing 8,000 redirects in .htaccess is possible, but Apache slows down parsing that file on every request, and manual editing is painful. Our redirect management module solves this by storing rules in the database with a convenient interface, importing from any format, and providing analytics.

With over a decade of experience on Bitrix and 500+ completed projects, we've built more than 50 such modules for clients ranging from e-commerce stores to large corporate portals.

Why a Module Is Better Than .htaccess

Apache noticeably slows down when the number of RewriteRule directives exceeds 500–1000: the file is parsed for every request unless caching is configured. Nginx reads the config once at startup, but restarting it for each new redirect in production is impractical.

Storing rules in the database and processing them with PHP is a compromise: slightly slower than a hardware-level Nginx redirect (by 20–30%), but it allows real-time rule management without service restarts. Plus, you get change history, hit statistics, import/export, and everything in the familiar Bitrix admin panel.

A cached handler runs 10 times faster than an uncached one: checking a redirect for a static URL takes under 1 ms.

What We Deliver

Component Description
Database table Fields: source, destination, code (301/302), regex flag, priority, hit counter
OnPageStart handler Checks static URLs via O(1) array, then regex by priority
Caching Bitrix tagged cache, auto-reset on rule changes, 1-hour TTL as safety net
.htaccess import Regex parser, imports with warnings for complex conditions
CSV import Validates duplicates and cyclic redirects
404 log Table myvendor_redirect_404 with hit frequency, one-click redirect creation
Statistics Sort by hits, identify unused rules (no hits in 90 days)
Documentation DB schema, API integration, operation manual

Architecture

Rule table:

CREATE TABLE myvendor_redirect ( id SERIAL PRIMARY KEY, source VARCHAR(500) NOT NULL, destination VARCHAR(500) NOT NULL, code SMALLINT NOT NULL DEFAULT 301, is_regex BOOLEAN DEFAULT false, priority INT DEFAULT 100, hits INT DEFAULT 0, active BOOLEAN DEFAULT true, created_at TIMESTAMP DEFAULT NOW(), created_by INT ); CREATE UNIQUE INDEX idx_redirect_source ON myvendor_redirect(source) WHERE NOT is_regex; CREATE INDEX idx_redirect_active ON myvendor_redirect(active, priority); 

Handler. Rules are loaded in the OnPageStart event. Static rules (exact URL match) are checked first via isset on an associative array — O(1). Regular expressions are evaluated only if no static match is found, iterating over rules sorted by priority.

AddEventHandler('main', 'OnPageStart', [\MyVendor\Redirect\Handler::class, 'handle']); 

Documentation for the OnPageStart event is available at dev.1c-bitrix.ru.

Caching. The entire rule list is cached with Bitrix tagged cache. When any rule changes, the cache is invalidated. TTL is 1 hour as a safeguard against missed cache busting.

Import from .htaccess and CSV

After a migration, clients typically have either an old .htaccess or an Excel file with old and new URLs. The module includes parsers for both.

.htaccess parser:

// Example line: RewriteRule ^old/(.*)$ /new/$1 [R=301,L] preg_match('/^RewriteRule\s+\^([^\$]+)\$?\s+(\S+)\s+\[([^\]]+)\]/', $line, $m); 

The module extracts source, destination, redirect code, and the regex flag. Rules with complex conditions (RewriteCond) are imported with a warning — they need manual review.

CSV import:

  1. Prepare a CSV file with columns old_url;new_url;code.
  2. Upload the file in the module's Import section.
  3. The module checks for duplicates and cyclic redirects.
  4. After successful validation, rules are added to the database.
  5. Verify redirects work via the 404 log.

Before import, validation includes: duplicate sources, cyclic redirect check (A → B → A), and optional destination reachability via HEAD request.

How We Detect 404 Errors

The module logs 404 responses to table myvendor_redirect_404. In the admin interface, a list of the most frequent 404 URLs is displayed with hit counts and a "Create redirect" button for each. This is the primary tool for migration: you see the most requested non-existent URLs and create redirects in one click.

Statistics and Analytics

Each redirect hit increments the hits counter. In the interface, you can sort rules by hits to identify popular redirects and, conversely, find "dead" rules (no hits in 90 days) that are candidates for removal.

A Real-World Case

For a large e-commerce site with 12,000 SKUs, migrating from /category/product.php?ID=123 to /category/subcategory/product-name/ generated over 3,000 404s. Our module imported the old URL mapping from a CSV file, validated for cycles, and implemented redirects with caching. The 404 count dropped to zero within a week, and organic search traffic recovered fully in 14 days.

Process and Timelines

Our typical workflow:

  1. Data collection — gather existing URL mappings, logs, and .htaccess files.
  2. Audit & Analysis — identify the most frequent 404s, assess impact.
  3. Design — define rule structure, caching strategy, and import format.
  4. Estimation — provide a fixed quote after analysis.
  5. Development — build the module with all required features.
  6. Testing — unit tests, import validation, and performance benchmarks.
  7. Launch — deploy and monitor 404 reduction.
Scope Features Timeline
Basic Rule table + handler + interface 1.5–2 weeks
Medium + regex + import from .htaccess/CSV + 404 log 3–4 weeks
Advanced + cycle validation + statistics + CDN integration 5–6 weeks

To get an accurate estimate for your project, contact us — we'll prepare a proposal based on your specific needs.

Common Mistakes to Avoid

  • Not clearing the cache after import — always flush the tagged cache to make new rules active immediately.
  • Ignoring trailing slashes — inconsistent use of trailing slashes causes misses; we recommend normalizing all URLs.
  • Using 302 permanently — use 301 for permanent moves, 302 for temporary, to avoid diluting link equity.
  • Forgetting to test — always test a sample of rules after import, especially regex ones, to ensure they match as expected.
Technical implementation details
  • OnPageStart handler uses Bitrix\Main\EventManager.
  • Cache is cleared via Bitrix\Main\Data\Cache::clearCacheByTag.
  • Supports PHP 8.1+ and MySQL 5.7+.

Contact our specialists to discuss your project — we'll help set up the import, verify integrity, and enable caching. Eliminate 404 errors and preserve your SEO traffic.