The URL's don't end with .php's (AFAIK that's what Location matches), but the PHP files do. I.e. the URL's look like /api/whatever, and are mapped to /index.php/api/whatever by Rewrite.
I think with such rewrites it wouldn't be possible to get what you want.
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName www.example.net DocumentRoot /vhosts/default/public_html <Directory /vhosts/default/public_html> DirectoryIndex index.html index.php Options -Indexes AllowOverride all Order allow,deny allow from all </Directory> SetEnv FCGI-PORT 9000 <LocationMatch \.php$> SetEnv FCGI-PORT 9001 </LocationMatch> <LocationMatch ^/api/> SetEnv FCGI-PORT 9002 RewriteEngine On RewriteRule (.*) /index.php?route=%{REQUEST_URI} [R=301,L] </LocationMatch> </VirtualHost>
Some basic tests
# curl http://www.example.net/ 9000 # curl http://www.example.net/index.php 9001 # curl -I http://www.example.net/api/whatever HTTP/1.1 301 Moved Permanently Date: Wed, 09 Mar 2016 17:03:56 GMT Server: Apache/2.2.15 (CentOS) Location: http://www.example.net/index.php?route=/api/whatever Connection: close Content-Type: text/html; charset=iso-8859-1 # curl http://www.example.net/index.php?route=/api/whatever 9001
But if we comment rewrite rules - all works as expected
# curl http://www.example.net/ 9000 # curl http://www.example.net/index.php 9001 # curl http://www.example.net/api/ 9002 # curl http://www.example.net/api/test.php 9002
Try changing their order.
in this particular case (with rewrites) the order doesn't matter
P.S. index.php/test.php it's just a simple php script
<?php echo $_SERVER['FCGI-PORT'];
/api/end with.php, cause if so, they're all getting matched by the first block. Try changing the order of the blocks to see if it helps..phpfiles are going to be matched by the first block. Try changing their order.