It is necessary to remove the extra slashes in the links of the form:

http://site.ru////page http://site.ru////page////catalog http://site.ru////page//// 

handles the latter

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

And what about the rest?

Tried to use what was offered in similar topics, but does not respond

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

UPD

 RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*) RewriteRule ^ %1/%2 [R=302,L,NE] RewriteRule (.+)/$ /$1 [L,R=301] 

parses everything except

 http://site.ru//// 

how to be?

    2 answers 2

    You solve the problem from the wrong end. Let's start with the key question: where do such links come from?

    If the source of "ugly" links is your site, then first of all you need to fix your site.

    If the source of "ugly" links is other sites, then they should be negligible. When linking to your site, most people will use the addresses that your site gives out, rather than inventing something on their own and arranging slashes from the bald.

    To search for sources of links, you can use a variety of analytics tools: Google Webmaster, Google Analytics, Yandex.Webmaster, Yandex.Metrica, etc.


    Now, when the source of links is no longer there, it may turn out that search engines still use "ugly" links. If this bothers you, enter the canonical address on each page.

    To do this, you can use <link rel='canonical'> , site maps, redirects, etc. In most cases, search engines cope with the detection of dulblirovannogo content on the site and take doubles as one page, and from the available URLs choose the most "beautiful", so you can not bother.

    See Use canonical URLs .


    .htaccess is a complex and inconvenient tool. You can add several rules to it, but the more complex the rules, the less readable the code becomes. If you run into the possibilities of .htaccess , then transfer all routing to the scripts and do not suffer.

    • one
      I will add that this problem in general form cannot be solved with .htaccess. The best solution would be to add a rule that, after finding two slashes in a row, sends to the router page. The router corrects the address and redirects it. - ReinRaus
    • I understand it. And nowhere is there a link to my site like site.ru////////catalog . But, at the same time, I want the user or machine, clicking on such a link, to go to the desired page, and not to 404 error. I solved the problem. The htaccess code is added to the post at the end. And for links like site.ru/// decided at the php script level, which interprets this address as just a request for index.php. - Floyat
     RewriteCond %{THE_REQUEST} // RewriteRule .* /$0 [R=301,L] 
    • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky