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:
<?$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?
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
- Correct URL processing rules setup
- Correct component parameters setup
- Alternative solutions
- Checking and debugging
Main reasons for the problem
The 404 error occurs due to several key factors:
-
Routing conflict: Your URL processing rule
#^/catalog/filter/([a-z0-9_\-\/]+)/apply/#points to the path/catalog/index.php, but the component is in thesections.phpfile, creating a mismatch between expected and actual paths. -
Incorrect root section processing: With
SECTION_ID = 0and enabled URL rewriting, the system may incorrectly interpret filter requests as attempts to access non-existent pages. -
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. -
Priority of URL processing rules: Your rule with
SORT = 90may 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:
'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=0for the root section - Changed the target path to
/catalog/sections.phpinstead 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:
<?$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:
- Replace
$_REQUEST["SMART_FILTER_PATH"]with$arResult["VARIABLES"]["SMART_FILTER_PATH"]for correct value retrieval from context - Explicitly set
SEF_MODE = "Y" - 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:
<?$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:
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:
-
Enable error display at the beginning of the
sections.phpfile:phpdefine("BX_SHOW_INCLUDE_TIME_EXEC", true); ini_set("display_errors", 1); error_reporting(E_ALL); -
Check variables:
phpecho "<pre>"; print_r($_REQUEST); print_r($arResult["VARIABLES"]); echo "</pre>"; -
Check generated URLs:
Enable Bitrix debug mode and see which URLs are generated by the component. -
Check URL processing rules:
Ensure your rule has the correct priority and doesn’t conflict with other rules. -
Check the 404.php file:
Ensure the404.phpfile correctly redirects to/catalog/sections.phpon 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.