I have two Laravel sites: a front page and an API site. My customer will later separate the API site on a subdomain, but for the time being the customer wants to serve the API from inside "subfolder" of the landing page (mostly because he does not have a wildcard SSL/TLS certificate yet). It should look like this:
http://example.com
- front page with possibly some subroutes, such as
http://example.com/contact-us
http://example.com/api/
- the API
I don't want to mix the code of both projects together; they are being maintained by different developers, so mapping the folder as an Apache VirtualHost seems the way to go.
I did as follows:
<VirtualHost *:80>
DocumentRoot "/sites/front-page/public"
ServerName somedomain.com
ServerAlias www.somedomain.com
<Directory "/sites/front-page/public">
AllowOverride All
Require all granted
</Directory>
Alias /api "/sites/api/public"
<Directory "/sites/api/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Now when I visit http://example.com/api/
it indeed calls index.php
from the API site. But if I call http://example.com/api/some-resource
it calls the index.php
from the front-page site, and that fails with 404 not found.
I tried also
AliasMatch "^/api(/|$)(.*)" "/sites/api/public"
but then even http://example.com/api/
root fails with Apache 403 forbidden page (http://example.com
and its routes work fine, though).
How do I tell Alias
to match /api
with all its subroutes and send the (.*)
part to Laravel's router?
Also, I most probably will have to edit .htaccess
Redirect rules in the other site to strip out the /api
part from the URL before passing it to Laravel's index.php
, but I'm not sure how to do it right.
In case if I'm doing it all wrong and there is another way to serve two different sites from the same domain, I'm open to suggestions.