Answer the question
In order to leave comments, you need to log in
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]
Answer the question
In order to leave comments, you need to log in
#*со страниц без слеша на слеш*
RewriteCond %{REQUEST_URI} !\?
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} !\/$
RewriteRule ^(.*[^\/])$ /$1/ [R=301,L]
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]
# Исключить слеш.
############################################################################
#### Добавляем слеш(/), если его нет, и это не файл. ####
############################################################################
RewriteCond %{REQUEST_URI} !(.*)/$
# Если слеша в конце нет.
RewriteCond %{REQUEST_FILENAME} !-f
# Не является файлом.
RewriteCond %{REQUEST_URI} !\..+$
# В URL нет точки (файл).
RewriteCond %{REQUEST_URI} ^(.+)$
# В URL есть хоть один символы
RewriteRule ^(.*)$ $1/ [L,R=301]
# Добавляем слеш в конце.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question