Search code examples
regexapacheweblogicslashlocationmatch

Apache LocationMatch regex ignores duplicate slashes


I'm having a strange behaviour with Apache's LocationMatch directive when there are extra slashes at the beginning of the URL. According to the Apache docs if I'm reading it right this should work:

    <LocationMatch ^/appcontext/(a|b)>

            SetHandler weblogic-handler
            WebLogicCluster apphost01:xxxx,apphost02:xxxx
            WLProxySSL ON

    </LocationMatch>

However if I type the following URL it is also being forwarded to the backend hosts:

https:// <hostname:port> ////////appcontext/a/

In the Apache docs it clearly states that it should apply the directive only for /appcontext/a/, unless I'm missing something with the regex or there is some issue with the mod_wl plug-in

http://httpd.apache.org/docs/2.2/mod/core.html

"For example, <LocationMatch ^/abc> would match the request URL /abc but not the request URL //abc"

Does anyone have any suggestion to achieve this?


Solution

  • Yes Apache does collapse extra slashes in rewrite rule. You can use THE_REQUEST variable to match and remove extra slashes. Place this in root .htaccess:

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} ^(.*?)//+(.*)$
    RewriteRule ^ %1/%2 [R=302,L,NE]