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.
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.