0

Using mod_rewrite like this:

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

I can delete last slash in links like example.com/foo/ But wat if i want to delete this last slash in example.com/ the rules used before dont work. The same in this example: If i want to delete 2 slashes

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

it works fine if link is somthing like example.com/foo//bar But if the link is example.com//foo/bar the rule does not work.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115

1 Answers1

0

you could:

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

You can add /? to the condition. I can't test right now but maybe works.

Mork
  • 365
  • 5
  • 18