NeuroAgent

Bitrix Smart Filter 404 Error in Catalog Root with URL Rewriting

Solution for 404 error when using filter in catalog root with enabled URL rewriting in Bitrix. Configuration of address processing rules and component parameters.

Why does the filter in the root of the catalog folder return a 404 error when URL rewriting is enabled? I implemented the filter in the sections.php file of the complex catalog component using the bitrix:catalog.smart.filter component. When trying to sort products through the filter, a 404 error occurs. If I disable URL rewriting in the filter settings, everything works correctly. What could be the cause of this problem?

Here’s the filter implementation code:

php
<?$APPLICATION->IncludeComponent(
	"bitrix:catalog.smart.filter",
	"",
	array(
		"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
		"IBLOCK_ID" => $arParams["IBLOCK_ID"],
		"SECTION_ID" => 0,
		"FILTER_NAME" => $arParams["FILTER_NAME"],
		"PRICE_CODE" => $arParams["~PRICE_CODE"],
		"CACHE_TYPE" => $arParams["CACHE_TYPE"],
		"CACHE_TIME" => $arParams["CACHE_TIME"],
		"CACHE_GROUPS" => $arParams["CACHE_GROUPS"],
		"SAVE_IN_SESSION" => "N",
		"FILTER_VIEW_MODE" => $arParams["FILTER_VIEW_MODE"],
		"SECTION_TITLE" => "NAME",
		"SECTION_DESCRIPTION" => "DESCRIPTION",
		'HIDE_NOT_AVAILABLE' => $arParams["HIDE_NOT_AVAILABLE"],
		"TEMPLATE_THEME" => $arParams["TEMPLATE_THEME"],
		'CONVERT_CURRENCY' => $arParams['CONVERT_CURRENCY'],
		'CURRENCY_ID' => $arParams['CURRENCY_ID'],
		"SEF_MODE" => $arParams['SEF_MODE'],
		"SEF_RULE" => "/catalog/filter/#SMART_FILTER_PATH#/apply/",
		"SMART_FILTER_PATH" => $_REQUEST["SMART_FILTER_PATH"],
		"PAGER_PARAMS_NAME" => $arParams["PAGER_PARAMS_NAME"],
		"INSTANT_RELOAD" => $arParams["INSTANT_RELOAD"],
		"SHOW_ALL_WO_SECTION" => "Y"
	),
	$component,
	array('HIDE_ICONS' => 'Y')
);?>

The URL processing rule:

18 => 
  array (
    'CONDITION' => '#^/catalog/filter/([a-z0-9_\-\/]+)/apply/#',
    'RULE' => 'SMART_FILTER_PATH=$1&',
    'ID' => '',
    'PATH' => '/catalog/index.php',
    'SORT' => 90,
  ),

When the 404 page output is disabled, the content of the section.php file is displayed instead. Please advise on how to solve this problem with the filter in the catalog root?

NeuroAgent

Main Problem with 404 Error When Using Filter in Catalog Root with URL Rewriting

The main problem with the 404 error when using a filter in the catalog root folder with enabled URL rewriting (ЧПУ) is related to a conflict between URL processing rules and the component structure. This is a common situation in Bitrix when the filter tries to use a URL that doesn’t match the existing page structure.

Contents

Main reasons for the problem

The 404 error occurs due to several key factors:

  1. Routing conflict: Your URL processing rule #^/catalog/filter/([a-z0-9_\-\/]+)/apply/# points to the path /catalog/index.php, but the component is in the sections.php file, creating a mismatch between expected and actual paths.

  2. Incorrect root section processing: With SECTION_ID = 0 and enabled URL rewriting, the system may incorrectly interpret filter requests as attempts to access non-existent pages.

  3. SMART_FILTER_PATH parameter: The value of $_REQUEST["SMART_FILTER_PATH"] may be empty or incorrect on initial page load, leading to incorrect URL formation.

  4. Priority of URL processing rules: Your rule with SORT = 90 may conflict with other catalog routing rules that have higher priority.

Correct URL processing rules setup

For the filter to work correctly in the catalog root, you need to configure the URL processing rules as follows:

php
'CONDITION' => '#^/catalog/filter/([a-z0-9_\-\/]+)/apply/#',
'RULE' => 'SMART_FILTER_PATH=$1&SECTION_ID=0&',
'ID' => 'CATALOG_FILTER',
'PATH' => '/catalog/sections.php',
'SORT' => 100,

Key changes:

  • Increased priority (SORT = 100) so the rule has more weight
  • Explicitly specified SECTION_ID=0 for the root section
  • Changed the target path to /catalog/sections.php instead of /catalog/index.php

Also ensure that in the .htaccess file or web server settings, 404 error handling is properly configured to redirect to /catalog/sections.php.

Correct component parameters setup

Your component code needs several important modifications:

php
<?$APPLICATION->IncludeComponent(
	"bitrix:catalog.smart.filter",
	"",
	array(
		"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
		"IBLOCK_ID" => $arParams["IBLOCK_ID"],
		"SECTION_ID" => 0,
		"FILTER_NAME" => $arParams["FILTER_NAME"],
		"PRICE_CODE" => $arParams["~PRICE_CODE"],
		"CACHE_TYPE" => $arParams["CACHE_TYPE"],
		"CACHE_TIME" => $arParams["CACHE_TIME"],
		"CACHE_GROUPS" => $arParams["CACHE_GROUPS"],
		"SAVE_IN_SESSION" => "N",
		"FILTER_VIEW_MODE" => $arParams["FILTER_VIEW_MODE"],
		"SECTION_TITLE" => "NAME",
		"SECTION_DESCRIPTION" => "DESCRIPTION",
		'HIDE_NOT_AVAILABLE' => $arParams["HIDE_NOT_AVAILABLE"],
		"TEMPLATE_THEME" => $arParams["TEMPLATE_THEME"],
		'CONVERT_CURRENCY' => $arParams['CONVERT_CURRENCY'],
		'CURRENCY_ID' => $arParams['CURRENCY_ID'],
		"SEF_MODE" => "Y",
		"SEF_RULE" => "/catalog/filter/#SMART_FILTER_PATH#/apply/",
		"SMART_FILTER_PATH" => $arResult["VARIABLES"]["SMART_FILTER_PATH"],
		"PAGER_PARAMS_NAME" => $arParams["PAGER_PARAMS_NAME"],
		"INSTANT_RELOAD" => $arParams["INSTANT_RELOAD"],
		"SHOW_ALL_WO_SECTION" => "Y",
		"SET_TITLE" => "Y",
		"SET_BROWSER_TITLE" => "Y",
		"SET_META_DESCRIPTION" => "Y",
		"SET_META_KEYWORDS" => "Y"
	),
	$component,
	array('HIDE_ICONS' => 'Y')
);?>

Important changes:

  1. Replace $_REQUEST["SMART_FILTER_PATH"] with $arResult["VARIABLES"]["SMART_FILTER_PATH"] for correct value retrieval from context
  2. Explicitly set SEF_MODE = "Y"
  3. Add SEO optimization parameters for better URL rewriting performance

Alternative solutions

Option 1: Move the filter to a separate section

If the problem persists, create a separate section in the catalog (e.g., “Product Selection”) and place the filter there, not in the root.

Option 2: Use the bitrix:catalog component

Instead of catalog.smart.filter, use the standard bitrix:catalog component with enabled filter settings:

php
<?$APPLICATION->IncludeComponent(
	"bitrix:catalog",
	"",
	array(
		"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
		"IBLOCK_ID" => $arParams["IBLOCK_ID"],
		"SECTION_ID" => 0,
		"ELEMENT_SORT_FIELD" => "sort",
		"ELEMENT_SORT_ORDER" => "asc",
		"FILTER_NAME" => "arrFilter",
		"INCLUDE_SUBSECTIONS" => "Y",
		"SHOW_ALL_WO_SECTION" => "Y",
		"HIDE_NOT_AVAILABLE" => "N",
		"TEMPLATE_THEME" => "site",
		"SEF_MODE" => "Y",
		"COMPONENT_TEMPLATE" => "smart_filter",
		// Other parameters...
	),
	$component
);?>

Option 3: Configure via URL_TEMPLATES

Add the following to the /urlrewrite.php file:

php
array(
    'CONDITION' => '#^/catalog/filter/([a-z0-9_\-\/]+)/apply/#',
    'RULE' => 'SMART_FILTER_PATH=$1&SECTION_ID=0&',
    'ID' => 'CATALOG_FILTER',
    'PATH' => '/catalog/sections.php',
    'SORT' => 100,
),

After this, clear the URL rules cache and regenerate them through the Bitrix interface.

Checking and debugging

To diagnose the problem, perform the following steps:

  1. Enable error display at the beginning of the sections.php file:

    php
    define("BX_SHOW_INCLUDE_TIME_EXEC", true);
    ini_set("display_errors", 1);
    error_reporting(E_ALL);
    
  2. Check variables:

    php
    echo "<pre>";
    print_r($_REQUEST);
    print_r($arResult["VARIABLES"]);
    echo "</pre>";
    
  3. Check generated URLs:
    Enable Bitrix debug mode and see which URLs are generated by the component.

  4. Check URL processing rules:
    Ensure your rule has the correct priority and doesn’t conflict with other rules.

  5. Check the 404.php file:
    Ensure the 404.php file correctly redirects to /catalog/sections.php on errors.

Most often, the problem is solved by correctly configuring URL processing rules and using correct parameters to pass SMART_FILTER_PATH. If the problem persists, it is recommended to create a separate section for filtering instead of placing it in the catalog root.