The .htaccess file below in my root directory serves to rewrite all /api/ then outputs the key value pairs from the URL from the $_GET inside /api/api.php?
How do I modify this so that all existing files or folders inside api (such as /api/test or /api/test/file.php accessed via this scheme will not rewrite via the rewrite rule?
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) $1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [QSA,L]
RewriteCond %{REQUEST_URI} ^/api
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^/]+)/ $1/$1.php?%1 [L]
</IfModule>
2
Answers
I made the following .htaccess file to include Directory index and fallback resource and placed it inside the the root directory to catch on each request from the root.
Also I put the rewritebase /api and InheritDown option to limit where I apply these rules and also recursively propagate down to directories that exist already so they (and nested files) will not get included in the rewrite process when requested.
This produced a successful result on $_GET where there were equal numbers of lhs (key) = rhs (value) pairs in the query string provided that they were entered as /api/lhs/rhs/lhs/rhs in in the request.
You can use
RewriteCond
directive to exclude your files and folders