Reputation: 3496
I own a website which gives every registered user a dedicated space like this:
www.mywebpage.com/user1
www.mywebpage.com/user2
www.mywebpage.com/user3
Inside this path the user has his mini web site.
I'd like to give my users not a path within my domain, but a second level domain like this:
user1.mywebpage.com
user2.mywebpage.com
user3.mywebpage.com
A lot of websites do this, but I can't figure out how to get it!
Am I supposed to register a CNAME in my dns record for every single user? How the hell can I achieve this with PHP? I don't think it's possible to configure godaddy with a human-hand written script.
I may register an alias CNAME which points every second level domain to my top domain, and then check within my top domain the first token of the url retrieving the user: but now I can't redirect him on a new page (which is the index of his subsite) or I'd lost the web url userx.mywebpage.com.
How can I handle this? I'd appreciate any hint about the right path to follow in order to achieve my goal.
Upvotes: 8
Views: 3943
Reputation: 302
The feature you want to see is often called Wildcard sudomain (usually blog sites have this feature).
Usually you make a CNAME record of * to represent the wildcard subdomain. Instead, with Godaddy make an A record with the name * and set the IP to your server. We have done with our ASP.net website in the past (not sure if works with GoDaddy still but give a try).
With a very little knowledge on PHP I can suggest adding some redirection(URL Rewrite) configuration in your httpd.conf or apache.conf file.
Please check this http://kbeezie.com/view/wildcard-subdomains-php/
after this you can write your own logic. All you need to do is find out your user from db which is in the subdomain name and render the pages.
Upvotes: 1
Reputation: 3362
You don´t have to set up dns entries for what you´re trying to achive. Depending on how much control you have over your website, in case you´re using Apache you can easily set up virtual hosts for your subdomains (see http://content.websitegear.com/article/subdomain_setup.htm)
Upvotes: 0
Reputation: 52372
Create a wildcard A record (*.mywebpage.com
) pointing to the IP of your server.
Create an Apache virtual host for ServerName *.mywebpage.com
, pointing all requests to the same document root. Your script looks at the hostname to know which user's site it is. You do not need to redirect outside of the user's subdomain. If your script sees the subdomain is "www", that's your special case where you display the main website instead of the user's stuff.
Upvotes: 5