GWed
GWed

Reputation: 15653

Use different domain and URLs with web application

Background

I have a web application that I host on my own server. I have clients who use the application as is, but some have asked if they can 'host' the application on their own server. This enables them to have their own URLS rather than mine. The application only forms part of their website so I'm assuming it will not be possible for my server to respond to a direct call to their domain etc

To give some examples, i currently have urls like www.mydomain.com/profile, www.mydomain.com/index.php?option=someoption&view=someview&id=1 What my clients' want is www.theirdomian.com/profile, www.theirdomian.com/index.php?option=someoption&view=someview&id=1 etc

Question

My question is, what is the best way for me to allow them to use their own URLs with my application, without giving them all the backend source code and databases to install on their server?

I dont really want to allow them to 'host' my application. But do want to enable them to use their own URLs, without having to modify anything on my server.

One way I thought would be to create a router.php file that sits on their server. When a link is clicked on the clients site, the router receives the request and modifies the url to get the data from my server etc. The route them outputs the html source back to the clients site via the calling URL.

Is this an effective way to achieve what I want, or is it way off the mark.

Upvotes: 1

Views: 1420

Answers (3)

Marcus Davies
Marcus Davies

Reputation: 248

ok!

lets say you have a PHP file hosted at http://www.mydomain.com/listener.php

that takes in post data

$Data = file_get_contents("php://input");

the posted data in this example is XML

<Myapp>
 <method="InitFunction"/>
 <User id="1234"/>
</Myapp>

the posted data here was delivered from a PHP file (i.e your API) that simply read data from the client input (as the API is on the clients server)

the API uses cURL to post to your file i.e http://www.mydomain.com/listener.php

depedning on what happens you can then respond i.e Print or ECHO the response back to the API.

check the php.net site for usage on cURL - it's very simpy to use

Upvotes: 0

deceze
deceze

Reputation: 522085

First of all, the links in your site should not be hardcoded. If you have hardcoded www.mydomain.com/... everywhere... good luck getting it out of there. You should use URLs relative to the server root, e.g.:

<a href="/profile">

For even more flexibility, use a helper that creates URLs relative to where the app is being run from instead of hardcoding any URLs. If that's done, all you need to do to access the same site using a different domain name is to configure the web server so it accepts requests for the domain name and setup the DNS entry for theirdomain.com to point to your server.

If that's not an option, the guys running theirdomain.com should run a reverse proxy that serves your domain under their domain.

Upvotes: 0

Marcus Davies
Marcus Davies

Reputation: 248

This maybe too advanced for your needs but...

can you not create some basic API that they can tap into, this will give them the freedom to utilise in there own way, whilst at the same time you retain control of it's behaviour.

the API will need nothing more than cURL and some simple XML

there are many ways to accomplish what you want, including mod_rewrite rules.

Upvotes: 1

Related Questions