Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Fri Mar 20, 2015 6:28 am 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
I have two laravel based PHP applications. One is an API server, the other a client-facing website.

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:

Code:
<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?


Top
   
PostPosted: Fri Mar 20, 2015 6:44 am 
Offline
Senior Newbie

Joined: Mon Aug 12, 2013 8:58 am
Posts: 14
Yes,

You need an Alias and another Directory directive... something like this:

Code:
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 https://httpd.apache.org/docs/current/m ... #directory and https://httpd.apache.org/docs/2.2/mod/mod_alias.html

I hope this helps.

Sid


Top
   
PostPosted: Fri Mar 20, 2015 7:08 am 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
Great, that seems to work for /api, but when I access /api/test, the 404 error handler of the website project is triggered, rather than the 404 error handler of the api project.


Top
   
PostPosted: Fri Mar 20, 2015 7:33 am 
Offline
Senior Newbie

Joined: Mon Aug 12, 2013 8:58 am
Posts: 14
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.


Top
   
PostPosted: Fri Mar 20, 2015 8:27 am 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
virtualsid wrote:
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

Code:
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group