E
E
Evgeny Bukharev2015-07-03 12:12:50
htaccess
Evgeny Bukharev, 2015-07-03 12:12:50

How to remove slashes at the end of url in .htaccess?

There is a rule

#Убираем слэш в конце
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

It works, removes slashes as needed, how should the rule be modernized so that it removes not only one slash, but also two or more?
Unfortunately, I'm not strong in regular expressions
Thanks for the answers
PS Surprisingly, when commenting, the slash from the url is still removed anyway

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ShamblerR, 2015-07-03
@ShamblerR

############################################################################
#### Убираем повторяющиеся слеши (/) в URL                              ####
############################################################################
RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
            #Проверяем, повторяется ли слеш (//) более двух раз.
RewriteRule . %1/%2 [R=301,L]
            #Исключаем все лишние слеши.

A
Alexey Ukolov, 2015-07-03
@alexey-m-ukolov

I’m not an expert in .htaccess regular expressions, of course, but in theory you need to replace (/) with (/+)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question