The URL-path that the RedirectMatch
(mod_alias) directive matches against has probably already had multiple slashes reduced (a necessary step when the request is mapped to the filesystem).
To test for multiple slashes you need to use mod_rewrite and check against the THE_REQUEST
server variable instead (in a preceding condition). THE_REQUEST
is "unprocessed" and contains the first line of the request headers as sent from the client, eg. GET /a//b/c/ HTTP/1.1
.
For example, try the following instead, near the top of the root .htaccess
file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s[^?]*//
RewriteRule (.*) /$1 [R=301,L]
This removes (via an external 301 redirect) multiple slashes anywhere in the URL-path part of the URL. (Although you should always test first with a 302 - temporary - redirect in order to avoid any potential caching issues.)
This uses the fact that the URL-path matched (and captured) by the RewriteRule
pattern has already had multiple slashes resolved away. The $1
backreference then uses this URL-path (less the multiple slashes) in the substitution string.
The regex \s[^?]*//
in the CondPattern tests for multiple slashes in the URL-path and ensures we don't match multiple slashes in the query string (if any) - which would otherwise result in a redirect loop.
Reference: