A
A
artyomkin2020-12-23 20:36:24
htaccess
artyomkin, 2020-12-23 20:36:24

How to remove slashes finally correctly without Google and experiments?

What we have:

DirectorySlash off

RewriteEngine on

RewriteCond %{HTTPS}_%{HTTP_HOST} ^(?|off_(?:www\.)?(.*)|on_www\.(.*)) [NC]
RewriteRule .* https://%1/$0 [R=301,L]

RewriteRule (.*)/$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]


What you need is to remove repeated slashes everywhere:

https://domain/// => https://domain
https://domain///page => https://domain/page
https://domain/page/ //page => https://domain/page
https://domain///page/// => https://domain/page
https://domain///page///page => https: //domain/page/page
https://domain///page///page/// => https://domain/page/page
https://domain/page///page => https:/ /domain/page/page

something like this, sort of understandable

Share a fully working version.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-12-23
@artyomkin

already got tired of writing that RewriteCond %{HTTPS}_%{HTTP_HOST} ^(?|off_(?:www\.)?(.*)|on_www\.(.*)) [NC is not necessary and Yandex perfectly understands the sequence of redirects . DOES NOT AFFECT SEO!

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