Why can't the CNC rule work in Bitrix?
There is a rule in urlrewrite.php
1 =>
array (
'CONDITION' => '#^/news/([0-9a-zA-Z-]+)/#',
'RULE' => 'ELEMENT_CODE=$1',
'ID' => '',
'PATH' => '/news/detail.php',
'SORT' => 100,
),
There is physically a /news folder and a file detail.php
In the setting of the URL pages of the news component, it is written #ELEMENT_CODE#
That is, at the address mysite.com/news/odna_novost
I have to get to the file detail.php, but this rule doesn't work, and I see page 404.
And all the other rules from the file urlrewrite.php they work.
I tried to raise the rule higher in the file. Now it is the first in the array , it still does not help. What can I do it?
1 answers
If you add an underscore to the regular line then everything works:
'CONDITION' => '#^/news/([0-9a-zA-Z-_]+)/#',
But provided that the URL has a slash at the end of mysite.com/news/odna_novost/
If you don't need a slash at the end of the URL then remove it from the regular list:
'CONDITION' => '#^/news/([0-9a-zA-Z-_]+)#'
On the site, it is recommended to use one logic: either all pages have a slash at the end or not. So there will be no confusion and there will be no duplicate pages in search engines.
Alternatively, to add a slash at the end of all pages, /
must be added to file .htaccess
the following lines:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*/[^/\.]+)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]