V
V
Vladislav Startsev2021-09-20 09:14:53
PHP
Vladislav Startsev, 2021-09-20 09:14:53

How to set up a link redirect in Bitrix without a slash at the end with it?

Example:
The correct link is https://skp02.ru/services/pechat-bannerov/ everything is fine, but if https://skp02.ru/services/pechat-bannerov then the section page is shown.
How to do if the user got to it and redirected to a normal link?

In htaccess I wrote:
RewriteRule ^(.*)$ https://%1/$1/ [R=301,L]
and

RewriteCond %{REQUEST_URI} ^/services/$
RewriteRule .* /services/$1/ [R=301,L]

Does not help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Alexandrov, 2021-09-20
@esvlad

#*со страниц без слеша на слеш*
    RewriteCond %{REQUEST_URI} !\?
    RewriteCond %{REQUEST_URI} !\&
    RewriteCond %{REQUEST_URI} !\=
    RewriteCond %{REQUEST_URI} !\.
    RewriteCond %{REQUEST_URI} !\/$
    RewriteRule ^(.*[^\/])$ /$1/ [R=301,L]

V
Viktor Taran, 2021-09-20
@shambler81

Vladislav Startsev ,
I have seen such a hat many times already.
Who even came up with this redirect?
RewriteCond %{REQUEST_URI} !\?
? - cannot physically be in %{REQUEST_URI} because it is not part of the url itself
, like RewriteCond %{REQUEST_URI} !\&
&- is allocated through RewriteCond %{QUERY_STRING}
In fact, everything that works here is
RewriteCond %{REQUEST_URI} !\=
If not =, but sorry, but what does it have to do with it? Most likely, the "master" that came up with this redirect was thinking about GET parameters, but, as I said above, they do not fall into REQUEST_URI
If not a point, but excuse me, where does the point come from?
And that 2 conditions, in principle, are not feasible,
2 of them are idiotic and do not satisfy the requirements
All that remains is the penultimate no slash at the end
And the rewrite rule itself.
That is, 10% of the entire rule works, the remaining 90% is idiot rubbish
. Now let's figure out
how it should actually be.
Everything is more complicated here, since there are a couple of conditions in which you cannot remove the slash.

RewriteCond %{REQUEST_URI} \..+$
   # Если файл содержит точку.
RewriteCond %{REQUEST_FILENAME} !-d
   # И это не директория.
RewriteCond %{REQUEST_FILENAME} -f
   # Является файлом.
RewriteCond %{REQUEST_URI} ^(.+)/$
   # И в конце URL есть слеш.
RewriteRule ^(.+)/$ /$1 [R=301,L]
   # Исключить слеш.

However, not everything is so simple, it is semantically correct to close the slash
ON SEO does not affect either one or the other, it is 100% infa, the absence of redirects from one to another affects what can give two urls.
BUT which URL with a slash or not does not affect!
BUT semantically the URL should be closed
however the slash after the file name gives 404 if it's just a file.
So we need to separate real files and urls generated by CNC by
adding this rule.
############################################################################
#### Добавляем слеш(/), если его нет, и это не файл.                    ####
############################################################################
RewriteCond %{REQUEST_URI} !(.*)/$
   # Если слеша в конце нет.
RewriteCond %{REQUEST_FILENAME} !-f
   # Не является файлом.
RewriteCond %{REQUEST_URI} !\..+$
   # В URL нет точки (файл).
RewriteCond %{REQUEST_URI} ^(.+)$
 # В URL есть хоть один символы
RewriteRule ^(.*)$ $1/ [L,R=301]
   # Добавляем слеш в конце.

And there are two rules at once, moreover, it is in this sequence that they should be in .htccess
during the work, I saw a lot of grief SEO specialists recommending such hats, and 90% of which redirects cannot work physically.
I also often saw the removal of apercases in URLs (which, of course, cannot be done either)
redirects to html, motivating the fact that Google thinks that this is static and validates them better, etc., etc.
All this is treated with one thing, the removal of this employee and the hiring of a more qualified SEO, and not a floating comrade in suspended animation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question