3

Currently, user profiles are in the format of website.com/username which is fine. However, some heavier users wish to use custom domain names. This is similar to Tumblr. Users are given a subdomain of username.tumblr.com but they are allowed to use an external domain which gets mapped to the subdomain. How do I go about this in PHP? Allowing users to use custom domain names?

Thanks so much in advance for the help!

Charles
  • 50,943
  • 13
  • 104
  • 142
Giles Van Gruisen
  • 961
  • 3
  • 13
  • 27
  • Are you using any Framework? or is just plain PHP? – camilo_u Dec 15 '11 at 05:46
  • 2
    I think there are a few questions here, the answers so far address how to create the wildcard subdomains like `username.tumblr.com`, but to implement custom domains like `username.com` will require several steps: 1. `username.com` needs to point to your server (say with a DNS A record). 2. `username.com` is stored with the user data in your database. 3. in your PHP code you watch the CGI variables for custom domains and take appropriate action. You may also need to configure your server (apache? iis? nginx?) to route all `port 80` traffic (regardless of domain) to your PHP app. – Daniel Mendel Dec 15 '11 at 06:22

2 Answers2

1

You can use the following examples:

Basic PHP:

How to let PHP to create subdomain automatically for each user?

CodeIgniter:

http://net.tutsplus.com/tutorials/php/basecamp-style-subdomains-with-codeigniter/

Zend Framework:

Query regarding subdomain redirection in Zend Framework

$routeitem = new Zend_Controller_Router_Route_Regex('(.*)',
                    array(1 => '', 'controller' => 'redir', 'action' => 'view'),
                    array(1 => 'hash'),
                    '%s'
    );

Drupal:

http://drupal.org/node/146344

Community
  • 1
  • 1
camilo_u
  • 1,380
  • 11
  • 20
0

You're after wildcard DNS; http://en.wikipedia.org/wiki/Wildcard_DNS_record

Unless you have your own server (as in a dedicated or VPS server where you can configure apache) this won't usually be possible as shared hosts normally won't allow this.

Here is a good guide on how you could set it up.

wyqydsyq
  • 1,992
  • 1
  • 20
  • 28