0

I have a project where users can create their own profiles. And the profiles will have sub-domain URLs like robert.blogger.com. So if that user has some domain of his own like robert.com. Then I want every request for robert.com to redirect to robert.blogger.com without changing the URL.

The URL should show robert.com/home.html, robert.com/aboutus.html etc. but actually code should be run from robert.blogger.com/index.html, robert.com/aboutus.html etc.

Is this possible? If so, how can this be done?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
IamLitto
  • 506
  • 5
  • 10
  • ServerName robert.blogger.com; ServerAlias robert.com – Mike B Dec 31 '13 at 13:51
  • You want someone else his website to run from yours? – putvande Dec 31 '13 at 13:51
  • possible duplicate of [Create subdomain per user](http://stackoverflow.com/questions/1806313/create-subdomain-per-user), http://stackoverflow.com/questions/4116898/how-do-i-create-personal-sub-domain-programmatically-with-php, http://stackoverflow.com/questions/12408582/virtual-subdomain-one-subdomain-per-user, http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php, http://stackoverflow.com/questions/183928/how-to-let-php-to-create-subdomain-automatically-for-each-user – Mike B Dec 31 '13 at 13:52
  • @ mikeB that question has no relation with this?? – IamLitto Dec 31 '13 at 13:57
  • @IamLitto They all talk about what you're asking for. You realize that the owner of robert.com is going to have to log into his DNS management tool and point his domain at your servers. There's no way for you to hijack his domain (for good reason). If you're unaware of all this you need to start by learning about the basics of DNS and apache configs. – Mike B Dec 31 '13 at 14:07
  • @mike B hey.. man... this is not hijacking & all... I will get that authority to point his domain to my server. Just forget about all these things,.. please say how can I acheive this by coding or any other settings??? – IamLitto Jan 02 '14 at 06:17

4 Answers4

0

This is not done with php.

The best way to accomplish this is via an HTACCESS redirect. Alternatively this can be done via a DNS A record, but would require elevated access.

place a file named (.htaccess) in the root directory of the domain that contains the following:

RewriteEngine On
RewriteRule * subdomain.domain.com [L]

iamien
  • 61
  • 4
  • I have a server with dedicated IP. Can you please advice how to redirect some domain to this server using DNS A record?? – IamLitto Dec 31 '13 at 14:11
0

Not possible in php unless you use curl. You need to setup a wildcard DNS record to catch all subdomains and send them to you web server. Then you need to setup Apache to catch all named virtual hosts and send it to a directory.

Njuguna Mureithi
  • 3,506
  • 1
  • 21
  • 41
0

I would just the header function. header("Location: http://"$user_name."blogger.com");

0

This will work

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domainname.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domainname.com
RewriteRule ^(.*) user/user.php?username=%1
ErrorDocument 404 /notfound.php
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
Brian
  • 14,610
  • 7
  • 35
  • 43
IamLitto
  • 506
  • 5
  • 10