I built a LAMP web application that let's users create their own profile page where they can upload their resume and portfolio. The url for a person's profile will be something like
http://jobbank.com/user/johndoe
John Doe registers the domain name http://johndoefreelancer.com and he wants it to point to http://jobbank.com/user/johndoe. Anyone who visits johndoefreelancer.com should not be aware that it's driven by http://jobbank.com/user/johndoe. This means that the browser url should persistently show addresses such as:
http://johndoefreelancer.com/aboutme (really points to jobbank.com/user/johndoe/aboutme)
http://johndoefreelancer.com/portfolio (really points to jobbank.com/user/johndoe/portfolio)
Additionally, clicking on any links [a href=""] should keep you at johndoefreelancer.com instead of sending you to jobbank.com.
My question is, what is the best way to achieve this?
I'm considering:
1) Give instructions to users on how to domain forward with masking
2) Instruct users to fillout the field $homeUrl in their User Profile information, which is saved to the database
3) In my PHP code, if $homeUrl exists, replace all [a href="$_SERVER['HTTP_HOST']"] with [a href="$homeUrl"]
Is this the right approach? Is there a better way?
An alternative approach would be to tell your users to point their domains to your IP and set them up as name-based virtual hosts. The benefits are:
- It's much easier for the user to set up then forward with masking (the latter may not even be possible depending on registrar)
- You don't have to deal with URL rewriting in your PHP code.
This would be easier to setup if you did not have to use /user/johndoe
prefix for your URLs (which you don't really need to because you can do a domain lookup in your code to determine user id), but is possible with the prefix as well - it's just that mod_rewrite setup would have to be more involved in that case (you'll need to do it per domain).
The only practical way i could think of in the moment is:
add a field in the users Profile
for a domainname
tell the users to let point the DNS host entry to your IP (or the main domainname of you)
create a virtual host which is the FIRST of alle vhosts you might have. (*)
in this virtual host create an index.php script which looks up the requested domainname in the user profile and display the page.
You might need to implement a switch for the urls you print on the page. eg. if you came over the special index page use / as "base href", in all other cases /user/username is "base href"
*) If apache gets a request for a name it dont know (because its no ServerName|Alias of an vhost, it uses the first Vhost as fallback.