Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a personal URL for all users to my site

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

like image 893
Abs Avatar asked Mar 26 '10 13:03

Abs


1 Answers

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.

like image 124
Andy Avatar answered Sep 28 '22 05:09

Andy