Apache location match wildcard URL

HGSSO picture HGSSO · Apr 17, 2012 · Viewed 7.2k times · Source

My VHOST currently looks like:

<VirtualHost *:80>
     DocumentRoot /data/sites/example_deploy
     ServerName deploy.example.co.uk
     <Directory "/data/sites/example_deploy">
        Options +SymLinksIfOwnerMatch
        AllowOverride All
        Order allow,deny
        Allow from all

        AuthUserFile /data/confs/svn/htpasswd
        AuthName "Example deployment example testing"
        AuthType Basic
        Require valid-user
    </Directory>
</VirtualHost>

We have a URL /api that takes different parameters. Examples are:

  • /api/testing-bot-response/1234842823
  • /api/sql-deploy-response/stage/172bUd7s

What we are trying to achieve is that /api/* would not require a valid user and the HTaccess is satisfied before the request is made. The URL may be made up of more than 2 parameters.

I've researched the subject and have worked out that I need to use LocationMatch and pass the Satisfy parameter, however I am not sure how the regular expression should be formed.

Answer

HGSSO picture HGSSO · Jan 30, 2019

I've resolved this issue. The trick is to use LocationMatch. Look at the below code:

$<LocationMatch "/api/*"> 
    order allow,deny 
    allow from all 
    Satisfy any 
</LocationMatch>