-1

I am building a SAAS product which is hosted on abc.com and i will have few clients with domains client1.com, client2.org, client3.in etc.

Now i want to serve my application to each client on their domains like client1.com/app, client2.com/app, client3/com/app

I dont want to host my code on their server..There will only be 1 base code & 1 DB which will be on my site abc.com. So my entire app should run on their domain

The question is, how do I configure this ? I mean client.com will point to their server but client.com/app will execute my application from my server with base url of their own domain ?

Thanks..

Jigar
  • 101
  • 3
  • hidden_4003 asks about using subdomains pointing to your server, I definitely agree that being much easier than using a subfolder to make this work. Far less complicated, and you won't have *anything* to maintain on client servers, especially if you use a CNAME that way if the IP ever changes, you don't even have to have your client's update their DNS. – Regan Oct 28 '13 at 13:11
  • I agree, but its all about client's requirement :) – Jigar Oct 28 '13 at 14:29

2 Answers2

2

The easiest method I can think of is to use mod_proxy (if using apache on the client's domains)

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Another way is to have a php script proxy the data:

<?php
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);1

/* Sends an http request to www.example.com
   with additional headers shown above */
$fp = fopen('http://www.example.com/app?q='.$_GET['q], 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>

If you can add a .htaccess, I would advise using .htaccess to redirect everything from app on using something similar to:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

You may have to do some tweaking for it to reside in /app. And then your wrapper script will have to learn to pass on the q=$1 variable to the host in a different way. My example is pretty raw and it's not checked for errors.

I'd also send a fixed query per site, with the domain. That way it's easier for your app to decipher where it's coming from and won't have to rely on IP addresses and such. Also, you'll have to deal with sessions too, as the wrapper as shown is not passing cookies all the way down to the client and back. And the abc.com domain is only going to see the IP of the server hosting the wrapper script.

Regan
  • 1,011
  • 1
  • 7
  • 15
  • what if client is using something else ? Also it would require me to make changes to his server config, right ? can it be avoided ? – Jigar Oct 28 '13 at 11:54
  • Well, you could make a wrapper script, one that fetches the stuff from your server. mod_proxy would be the easiest in my opinion but if you can't modify their config a wrapper script might be required. I'll update the post with a wrapper script you might be able to modify. – Regan Oct 28 '13 at 12:01
  • Accepting your answer for suggesting mod_proxy.. honestly, I didn't try the wrapper script since I was busy in getting this worked with mod_script :p thanks – Jigar Oct 28 '13 at 14:24
2

If you asked your client to setup the DNS domain app.client1.com, and point it to your server, it would be a much cleaner and unobtrusive approach. No proxy or anything like that.

Or could you elaborate why you need a client1.com/app/ URI?

Chris S
  • 77,945
  • 11
  • 124
  • 216
hidden_4003
  • 164
  • 3
  • yes, I agree that it is much cleaner & easier solution.. But the client doesn't want it that way :( – Jigar Oct 28 '13 at 14:25