Apache vhost serving different directory for HTTP path
To avoid cross-origin issues when doing AJAX calls, I prefer to keep the API server and the website on the same domain. I.e.:
www.domain.com/* (requests served from a website project folder)
www.domain.com/api/* (requests server from an api project folder)
For the website, I have an Apache virtual host like so:
<virtualhost *:80="">ServerAdmin email@domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /home/mainuser/www/website/public
Options Indexes FollowSymLinks MultiViews
<directory home="" mainuser="" www="" website="" public="">Require all granted
AllowOverride all</directory></virtualhost>
This works fine, but now I would like to add a special case where all requests to domain.com/api/** are served by the directory /home/mainuser/www/api/public rather than /home/mainuser/www/website/public. Can this be specified in the virtual host?
4 Replies
You need an Alias and another Directory directive… something like this:
Alias /api /home/mainuser/www/api/public
<directory home="" mainuser="" www="" api="" public="">[your config for this directory, e.g.:]
Require all granted
AllowOverride all</directory>
Check out
I hope this helps.
Sid
I don't have a fancy error handler, so I've not come across this issue myself.
@virtualsid:
Do you have an ErrorDocument stanza anywhere in your virtualhost config? Perhaps even in a .htaccess somewhere?
I don't have a fancy error handler, so I've not come across this issue myself.
I had to add
RewriteBase /api
To the .htaccess inside /api
Now it works. But I wonder why?
My source is http://forumsarchive.laravel.io/viewtopic.php?id=14341