Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable user custom domains in PHP

I'm having a system where users can input their purchased domain into their profile, so when accessing their domain, it should replace their custom domain, e.g.

http://domain.com/custom-name to http://purchaseddomain.com.

So when they access their purchase domain, it should take them to their profile including their navigation links, such as links on their page will be replaced with their purchased domain, for example viewing their records would be:

http://domain.com/custom-name/records to http://purchaseddomain.com/records.

Tumblr enables this feature, however I have no idea how this all works:

enter image description here

This is exactly how I like to have a feature like this, I've searched on SO, but it didn't seem to help.

Now this is a problem, I'm not sure how I can validate, confirm and merge their purchased domain into my server without a problem using PHP - I'm using Codeigniter for this.

Is there a solid, stable plugin/library or detailed tutorial that can have the ability to enable custom domains masking a internal domain?

My server is running Ubuntu 11.10 on nginx 1.0.6.

The templating will be just fine for me, which I can do - all I need help on is how to safely accept and merge their domain to my server.


EDIT: Just looked into nginx VirtualHostExample, this looks good overall but how will I be able to dynamically add/remove those domain entries while the domain has an A record pointing to my server?

like image 485
MacMac Avatar asked Jan 29 '12 21:01

MacMac


1 Answers

You won't merge their domain to your server.

In fact, when they will register their domains, they will make it point to your server.

On your server configuration, you'll have to dynamically create rules that implicitly redirect the page to the one they created on your server.

So, users will see http://purchaseddomain.com/on-uri but you serve the page http://domain.com/custom-name/one-uri

I.E: it's like if you added on an .htaccess - even if you don't use apache, it's just to explain what the "system" must be:

RewriteCond %{HTTP_HOST} purchaseddomain\.com$ [NC]
RewriteRule (.*) /custom-name/$1
like image 107
dievardump Avatar answered Nov 13 '22 10:11

dievardump