I
I
Ivan2020-08-06 15:21:46
1C-Bitrix
Ivan, 2020-08-06 15:21:46

How to make correct urlrewrite?

The goal is to do proper url processing by writing a regular expression in urlrewrite.php

Now implemented like this

$arUrlRewrite=array (
  0 => 
  array (
    'CONDITION' => '#^/uslugi/([a-z-0-9_]+)/([a-zA-Z0-9\\.\\-_]+)/?.*#',
    'RULE' => 'SECTION_CODE=$1&CODE=$2',
    'ID' => '',
    'PATH' => '/uslugi/detail.php',
    'SORT' => 100,
  ),
  1 => 
  array (
    'CONDITION' => '#^/uslugi/([a-zA-Z0-9\\.\\-_]+)/?.*#',
    'RULE' => 'SECTION_CODE=$1',
    'ID' => '',
    'PATH' => '/uslugi/index.php',
    'SORT' => 100,
  ),
);


But I want to make sure that all links have a slash at the end without any redirects to htacces

If I remove ?.* after the slash in the regular expression, everything works and links without a slash lead to a 404 page, but with a slash they open. But if there is a request at the end of the link? for example: utm label ?utm=Hi or GET link also leads to 404, which shouldn't happen This option also doesn't work for some reason
'CONDITION' => '#^/uslugi/([a-zA-Z0-9\\.\\-_]+)/#,

'CONDITION' => '#^/uslugi/([a-zA-Z0-9\\.\\-_]+)/(?.*)#',
    'RULE' => 'SECTION_CODE=$1$2',


Good people, plz tell me how to implement this task without redirects, SEO specialists and site owners will surely thank you! =)

In general, I don’t understand why to produce extra redirects, if you can somehow give search robots a clear link

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serginhold, 2020-08-06
@serginhold

from the point of view of the regular expression, special characters need to be escaped, in the second option, put a backslash before the question mark

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question