Tell me more ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

In my site i want to add an functionality for user to use their username with domain.

Like in codeigniter right now i want to give the user to use their own url to login in site and do other stuff.

For eg:

i Want www.username.mysite.com/login or www.username.mysite.com/category

so here the user can login with their credential and add the category. so i have two controller in my site with login and category.

So how to do this with the routes Or .htaccess.

share|improve this question
How do you create the sub-domain in the web server? When the user registers do you take their user name and create the sub-domain or virtual host? – Anagio Mar 16 '12 at 18:36

closed as off topic by John Conde Dec 24 '12 at 14:24

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

3 Answers

The solution you suggested is impractical and complicated.

Using PHP, you could simply use the global variable $_GET and format the URL such as this;

www.mysite.com/category?username=johndoe
share|improve this answer

I would suggest having a controller such as 'user', in which you override the routing by using the 'function remapping' functionality, which is described here. In this way you could have a single 'catch all' controller / url path which you can have code inside which grabs the username and loads up relevant content.

share|improve this answer

U can achieve this using controller

First configure *.urdomain.com to ur IP in A record

This will redirect subdomains to same ip

Configure ur apache vhost

<VirtualHost *:80>  
    DocumentRoot "/Users/folder"  
    ServerName *.urdomai.com
    ServerAlias *.urdomai.com
    <Directory "/Users/folder">  
        Options -Indexes  
        Options FollowSymLinks  
        AllowOverride All  
    </Directory>  
</VirtualHost>  

Add this line in config:

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"){$ssl_set = "s";} else{$ssl_set = "";}
$config['base_url'] = 'http'.$ssl_set.'://'.$_SERVER['HTTP_HOST'];

<?php  
class Dashboard extends Controller {  
    function Dashboard()  
    {  
        parent::Controller();  
        $subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2); //creates the various parts  
        $subdomain_name = $subdomain_arr[0]; //assigns the first part  
        if( $subdomain_name == "user1" )
{
//add ur code
}
    }  
}  
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.