How to Place the bitrix:news Component in the Website Root in 1C-Bitrix: SEF URLs and Routing Configuration
The bitrix:news composite component in 1C-Bitrix allows developers to create news sections, blogs, article libraries, and other content-driven sections using information blocks (iblocks). Typically, the component is placed in a separate directory, such as /news/index.php. However, some projects require displaying the news list directly on the homepage while making detail pages accessible through URLs relative to the website root.
In this guide, we will explain how to place the bitrix:news component in the website root, configure search engine friendly URLs (SEF), and prevent routing conflicts with other website sections.
Features of Placing bitrix:news in the Website Root
When the component is placed in the standard /news/ directory, the SEF_FOLDER parameter is usually set to /news/. However, when the component is included in the root /index.php file, the value / is used to configure URLs relative to the website root.
Keep in mind that the website root may contain other components, sections, and individual pages. Overly broad URL rewriting rules can intercept requests intended for unrelated parts of the website.
In our example, we will use the following URL structure:
/— homepage displaying the news list;/sections/company/— news category page;/news-example.html— individual news detail page.
This approach allows you to display the composite component on the homepage while maintaining separate routes for news categories and individual articles.
1. Including the bitrix:news Component in index.php
Open the /index.php file located in the website root directory and add the composite component call. If the file already contains other homepage elements, create a backup before making any changes.
Example contents of /index.php:
<?php
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php");
$APPLICATION->SetTitle("News");
$APPLICATION->IncludeComponent(
"bitrix:news",
".default",
array(
"IBLOCK_TYPE" => "news",
"IBLOCK_ID" => "1",
"NEWS_COUNT" => "20",
"CHECK_DATES" => "Y",
"USE_SEARCH" => "N",
"USE_RSS" => "N",
"USE_FILTER" => "N",
"SEF_MODE" => "Y",
"SEF_FOLDER" => "/",
"SEF_URL_TEMPLATES" => array(
"news" => "",
"section" => "sections/#SECTION_CODE_PATH#/",
"detail" => "news-#ELEMENT_CODE#.html"
),
"AJAX_MODE" => "N",
"SET_TITLE" => "Y",
"ADD_SECTIONS_CHAIN" => "Y",
"ADD_ELEMENT_CHAIN" => "Y",
"INCLUDE_IBLOCK_INTO_CHAIN" => "N",
"DISPLAY_NAME" => "Y",
"LIST_ACTIVE_DATE_FORMAT" => "d.m.Y",
"DETAIL_ACTIVE_DATE_FORMAT" => "d.m.Y",
"DISPLAY_TOP_PAGER" => "N",
"DISPLAY_BOTTOM_PAGER" => "Y",
"PAGER_TITLE" => "News",
"STRICT_SECTION_CHECK" => "N",
"CACHE_TYPE" => "A",
"CACHE_TIME" => "36000000",
"CACHE_FILTER" => "N",
"CACHE_GROUPS" => "Y",
"SET_STATUS_404" => "Y",
"SHOW_404" => "Y"
),
false
);
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php");
?>
Important: Replace the IBLOCK_TYPE and IBLOCK_ID parameters with the actual values of your information block. Make sure that all elements have valid symbolic codes, as these are used to generate detail page URLs.
2. Configuring SEF URLs for News in the Website Root
The main parameters responsible for routing in the composite component are:
SEF_MODE— enables search engine friendly URLs;SEF_FOLDER— specifies the base path used to generate URLs;SEF_URL_TEMPLATES— defines URL patterns for the news list, categories, and detail pages.
To place the component in the website root, use the following configuration:
"SEF_MODE" => "Y",
"SEF_FOLDER" => "/",
"SEF_URL_TEMPLATES" => array(
"news" => "",
"section" => "sections/#SECTION_CODE_PATH#/",
"detail" => "news-#ELEMENT_CODE#.html"
),
Here, #SECTION_CODE_PATH# is replaced with the category path, while #ELEMENT_CODE# is replaced with the symbolic code of the news item.
The news- prefix in detail page URLs is intentional. It helps distinguish news articles from other files and pages located in the website root.
3. Configuring the urlrewrite.php File
After enabling SEF mode, check the URL rewriting rules in the /urlrewrite.php file.
When working with a composite component located in the website root, it is especially important to avoid using a universal condition such as #^/# unless absolutely necessary. Such a rule can match almost any URL and may interfere with the routing of other components.
For our example, you can add two separate rules to the $arUrlRewrite array:
array(
"CONDITION" => "#^/sections/#",
"RULE" => "",
"ID" => "bitrix:news",
"PATH" => "/index.php",
"SORT" => 100,
),
array(
"CONDITION" => "#^/news-[a-z0-9_-]+\.html$#",
"RULE" => "",
"ID" => "bitrix:news",
"PATH" => "/index.php",
"SORT" => 100,
),
Note: These rules must be added to the existing array. Do not replace the entire contents of the urlrewrite.php file.
The first rule handles requests to news categories, while the second rule processes detail page URLs containing the news- prefix. In both cases, the request is directed to the root /index.php file, where the component determines which page to display based on the requested URL.
If the component has automatically registered a broader rule for the website root, review it and replace it with more specific conditions if necessary. Existing URL rewriting rules for other website sections must remain intact.
4. Configuring Information Block URLs
To ensure that news pages work correctly, check the URL settings in the information block itself.
Open the 1C-Bitrix administration panel, navigate to the settings of the relevant information block, and review the URL templates for categories and elements.
For the URL structure used in this example, you can specify:
Section page URL:
#SITE_DIR#sections/#SECTION_CODE_PATH#/
Element detail page URL:
#SITE_DIR#news-#ELEMENT_CODE#.html
These URL templates must match the routing configuration defined in the component.
If you are using a custom news.list template, also check how links are generated. In most cases, you should use the existing $arItem["DETAIL_PAGE_URL"] value when linking to detail pages instead of manually adding directories or prefixes.
5. Testing the Component
After completing the configuration, test the following scenarios:
- Opening the homepage at
/displays the news list from the specified information block. - Navigating to
/sections/company/opens the corresponding news category. - Opening a URL such as
/news-example.htmldisplays the detail page of the news item. - Other website sections, such as
/catalog/or/contacts/, continue to work correctly. - Requesting a nonexistent news article returns the correct HTTP 404 status.
If a detail page does not open, check the element's symbolic code, SEF settings, the contents of urlrewrite.php, and the server's URL rewriting configuration.
If the homepage or another component appears instead of the requested news article, review the URL conditions for overlaps and verify the order in which rewriting rules are processed.
6. Common Problems and Solutions
All Website URLs Are Processed by the News Component
This issue is usually caused by an overly broad regular expression in urlrewrite.php. When placing a composite component in the website root, use dedicated URL prefixes and specific routing conditions to prevent the component from intercepting unrelated requests.
News Detail Pages Return a 404 Error
Verify that the detail URL template matches the actual URL, that the news element has a valid symbolic code, and that the corresponding rewriting rule exists. Also make sure the element is active and accessible on the current website.
Links Still Point to the /news/ Directory
This may happen when the previous SEF_FOLDER settings are still in use, the information block contains outdated URL templates, or a custom component template generates links using hardcoded paths.
Old URLs Continue to Open After Changing SEF Settings
Check the current URL rewriting rules, clear the component cache, and verify that no additional redirects or server rules are generating the previous URL structure.
Conclusion
Placing the bitrix:news composite component directly in the website root in 1C-Bitrix is possible without modifying the standard component logic. You only need to include the component in /index.php, configure SEF_FOLDER and the URL templates, and add the appropriate rewriting rules to urlrewrite.php.
The main challenge is not including the component itself, but correctly distributing URLs between news pages and the rest of the website. Using clear URL prefixes and separate routing rules helps prevent conflicts and maintain a clean, predictable website structure.