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
After a lot of tweaking I found a solution just posting it here if someone stumbles upon this question - renamed the api-index.php and webapp-index.php to just index.php now just going to /sys/api/ or /sys/webapp/ doesn't lead to nowhere! - sent the path parameter in a htaccess file in each public directory so this is the structure:
sys
api
public
index.php
.htaccess [2]
webapp
public
index.php
.htaccess [3]
.htaccess [1]
[1]:
RewriteEngine On
RewriteRule ^api/(.*) api/public/$1 [L]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteRule ^(.*)$ webapp/public/$1 [L]
[2] and [3]:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]