I'm building an application with php that offers both an API interface and a web app(HTML) Interface. I have both of these in a directory in my document root:
/www/sys/api
and /www/sys/webapp
in each directory I have a router which is supposed to handle routing
/www/sys/api/public/api-index.php
/www/sys/webapp/public/webapp-index.php
Now what I want to do is to use a .htaccess file in my /www/sys/
to route any request in the form of /www/sys/api/smth/smth/smth
to /www/sys/api/public/api-index.php?path=smth/smth/smth
and any other request (anything other than www/sys/api
such as /www/sys/hello
or just /www/sys/
) to /www/sys/webapp/public/webapp-index.php?path=smth
.
Right now I have this:
RewriteEngine On
RewriteRule ^api/(.+)$ api/public/api-index.php?url=$1 [L]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_URI} !^api/public/api-index.php
RewriteRule ^(.+)$ webapp/public/webapp-index.php?url=$1 [L]
which is working to some extent except that:
going to server/sys/api/ sends me to server/sys/webapp/public/webapp-index.php but if I just add one more layer server/sys/api/hhh it works!
I'm not getting the full url param if I'm redirected to webapp I always get webapp/public/webapp-index.php and in API I always get public/api-inedx.php
to conclude I need to get this .htaccess to redirect /sys/api/ to /sys/api/api-index.php and get the actual url right. Thanks in Advance