-1


Let's say I have a website called http://mysite.dev

What I have:

So the urls of some pages will be below.

Home page: http://mysite.dev or http://mysite.dev/site/index or http://mysite.dev/home (site/index has been routed to home)

Edit Profile: http://mysite.dev/user/edit or http://mysite.dev/edit-profile (user/edit has been routed to edit-profile)

Admin Dashboard: http://mysite.dev/admin/ or http://mysite.dev/admin/index

Admin View Users: http://mysite.dev/admin/users or http://mysite.dev/admin/users/index

Admin Edit User: http://mysite.dev/admin/users/edit/1

So, basically my url pattern is as below.

http://mysite.dev/{module}/{controller}/{action}/{params}

What I need:

While keeping the main site as above, I need to have sub websites (micro websites) which will share the same login in the main site.

So that, the url pattern would be as below.

http://mysite.dev/{microsite}/{module}/{controller}/{action}/{params}

(microsite is empty means its the main website. There will no be any directory to represent the microsite since its just a reference as a name.)

That means, this microsite will not have sub directories since it the microsite name will be dynamic.

What I need to know:

How can I implement that url pattern either using .htaccess or url routing to develop this dynamic microsites.


Thank you!

asankasri
  • 476
  • 1
  • 6
  • 18
  • what makes the microsite a microsite? because if you don't have any other requirements than showing a view - e. g. no seperate dbs or tables - then {microsite} would just be another URI and you could either organize controllers in subdirs https://ellislab.com/codeigniter/user-guide/general/controllers.html#subfolders or make routes to accomodate that – mgrueter Sep 16 '15 at 10:38
  • @mgrueter, this microsite name will be dynamic. That's why I'm facing a difficulty to use codeigniter routing to do this. And based on this microsite name, I will be loading separate dbs. But there is a common db which has got the user table, that's why there is global login. – asankasri Sep 16 '15 at 10:44
  • I guess by "dynamic" you mean it could be whatever - because at some point you will need a check, to determine if this microsite exists and that means you need a list of microsites - be it as a set of routing rules or as an entry in a database (you'll also have to make sure, that your microsite can't be named something like "home" or "about-us"). So depending on your requirements, you either need to look into a multi-tenancy solution, or you can use wirezdesigne HMVW solution, or just solve this by having a set of controllers in subdirectories. – mgrueter Sep 16 '15 at 10:49
  • @mgrueter, you have get what is my requirement. Of course, this microsite name should be a valid name where I should be keep these list in somewhere, probable in a db table. It's better not to have seperate controllers, but I will try for your suggestion. – asankasri Sep 16 '15 at 11:04

1 Answers1

1

Okay I think I have got my head around this one!

Firstly, you will need to organise the main site and each microsite into their own subdirectories (for controllers, models, views, etc), such as:

application/controllers/main_site/module/etc
application/controllers/micro_one/module/etc
application/controllers/micro_two/module/etc

Then inside the routes folder you would do something similar to the following pseudo code:

Create array of microsite names (maybe get these from database)

Get the first URI segment

If URI segment is in microsites array
  $route['home'] = "{uri_segment/microsite_name}/module/controller";
else
  $route['home'] = "main_site/module/controller";

So for example your microsites array may be:

array('micro_one', 'micro_two')

Then the URL http://mysite.dev/micro_one/home would route to

$route['home'] = "micro_one/home/index";

I hope I have explained this enough for you to get started on your project!

James Walker
  • 795
  • 2
  • 6
  • 22
  • "you will need to organise the main site and each microsite into their own subdirectories (for controllers, models, views, etc)", is that mean i have to repeat and maintain the same code in each subdirectory? I hope it would not be practical. – asankasri Sep 17 '15 at 03:04
  • Is it only the database connection that would need to change for each "microsite"? – James Walker Sep 17 '15 at 09:31
  • Yes. Db connection need to changed and I must check whether that logged in user has the authority to view that microsite. – asankasri Sep 18 '15 at 07:51