views:

129

answers:

1

Hello all,

When a user registers with my site I want to offer them a login page and a user area with the URL:

http://user1.mysite.com http://user2.mysite.com http://user3.mysite.com ...

I did a google search for this but I wasn't sure of the right terms...

How can I do this without having to actually create lots of subdomains - I am sure its not done this way - is it URL re-writing? Apache mod_rewrite?

If so can someone give me an example please or is there a better way of doing this?

Btw, I am using Codeigniter - if Codeigniter has something that can do this, I would rather use that.

Thanks all for any help

+7  A: 

In your apache vhost definition (vhost.conf or whatever you have configured), create a wildcard alias

<VirtualHost *:80>
    ServerName   mysite.com
    ServerAlias  *.mysite.com

Then when the user hits your page, parse their URL (using parse_url()) to provide the correct login page/get their attempted username etc. Don't forget to duplicate the alias to your *:443 VirtualHost definition if you need to.

Andy
is there a limit on how many users it can have?
Sinan
How would I maintain this URL user.mysite.com throughout the users session. I mean they can move from different pages in their user area.
Abs
@Sinan no limit
Andy
@Abs do you mean they move between different subdomains? Set cookies like this http://www.jotlab.com/2008/04/08/howto-get-cookies-across-subdomains-php/
Andy
@Andy I mean the user stays within the same subdomain, but goes to pages like user1.mysite.com, then user1.mysite.com/1 then user1.mysite.com/2. I am trying to work out how this will work in my mvc framework.
Abs
I don't want actual subdomains, just the perception that a user has their own subdomain -would the ServerAlias server this purpose and not create or think these domains actually exist. Would I have to do anything with the my DNS setup to make use of this?
Abs
@Abs the domain is `mysite.com`, subdomain is X in `x.mysite.com`. MVC is on `mysite.com`, X is an alias for `mysite.com`. DNS setup is the same, create `*.mysite.com IN A 123.123123.123`
Andy
Ah I see- thanks Andy :)
Abs