How to load an codeigniter application by using different url

558 views Asked by At

Now I am developing an application by using CodeIgniter framework. In this application, there is a section which name account setup. By using this section we can create multiple accounts. As an example, accounts name are abc, bca or anything. And Suppose my site URL is: www.xyz.com (base_url) Then we need to access the site by the domain name and also domain name with account name like bellow:

www.xyz.com

www.xyz.com/abc/

www.xyz.com/bca/

www.xyz.com/anything/

For More clear, URL pattern will be:

www.xyz.com/dashboard/index

www.xyz.com/abc/dashboard/index

www.xyz.com/bca/dashboard/index

How can we do it? I need your suggestion.

2

There are 2 answers

0
Yaseen Ahmad On BEST ANSWER

Yes it's Possible through codeigniter Routs. Go to application\config Open a file which Name is routes.php you can call the controller functions see in code example

example

$route['new_project'] = "controller/function";

when you hit your website url like this www.xyz.com/new_project it will go to your mention controller and function.

see the documentation of routs CodeIgniter URI Routing

example 2:

$route['account/(.*)']    = "controller/function";

Now we you redirect your url like this

redirect('account/'.$name_var.'');

Now your url look like this.

www.xyz.com/account/name_of_logged_in_user

Also you can use this like this.

$route['(.*)/dashboard/index']    = "controller/function";

And then you can call it like this.

redirect(''.$name_var.'/dashboard/index');

And from this code your output url show something like this.

www.xyz.com/name_of_logged_in_user/dashboard/index

Hope it will help you if any question add comment

0
Ankit vadariya On

There are many way to do it.

1) Domain alias if you want to run same script with different domain.

2) if you want to run same script with sub domain then you can do it from Cpanel

3) If you want to run same script with different folders in same domain then you need to use htaccess