A
A
AgeWalker2020-10-13 17:40:17
htaccess
AgeWalker, 2020-10-13 17:40:17

How to set the redirect condition of several / (slashes) to 1 in the htacces file in RewriteCond?

Good afternoon!
The question arose of redirecting several slashes to one.
With this code, we were able to remove the extra / (slashes) at the end of the URL:

# Убираем повторяющиеся слеши (/) в URL
RewriteCond %{THE_REQUEST} ([^\s]*)\/{2,}(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]
# END Убираем повторяющиеся слеши (/) в URL

That is, instead of the URL:
web.com/page/superpage/////
we got:
web.com/page/superpage/

Now the question is how to remove / (slashes) from the inside of the URL, wherever they are.
That is, this URL:
web.com/page//////superpage/ and web.com/page//////superpage//////
Became
web.com/page/superpage/

The top code removes only slashes at the end of the URL, but not in the middle.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-10-13
@AgeWalker

https://klondike-studio.ru/standards/standartnyy-h... I
wrote in detail here.
If right for the task then

RewriteCond %{THE_REQUEST} //
   # Проверяем, повторяется ли слеш (//) более двух раз.
RewriteCond %{QUERY_STRING} !http(s|)://
  # Убедимся что это не урл в  GET
RewriteRule .* /$0 [R=301,L]
   # Исключаем все лишние слеши.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question