CodeIgniter Forums
controller as a subdomain - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: controller as a subdomain (/showthread.php?tid=12328)



controller as a subdomain - El Forum - 10-15-2008

[eluser]x386[/eluser]
Is this possible to access controllers not only by site.com/controller and have something like this: controller.site.com?
Thanks!


controller as a subdomain - El Forum - 10-15-2008

[eluser]meigwilym[/eluser]
Try the search - it works wonders!

Subdomaining

Mei


controller as a subdomain - El Forum - 10-15-2008

[eluser]x386[/eluser]
This is about redirecting user. I hate redirecting! Though, in the CPanel I have options for it. Anyway to access controller without redirecting via subdoamin? like: controller.domain.com will be same as domain.com/controller

Thanks!


controller as a subdomain - El Forum - 10-15-2008

[eluser]Colin Williams[/eluser]
I would use mod_rewrite rules to the effect of (.*).domain.com/(.*) index.php/$1/$2


controller as a subdomain - El Forum - 10-15-2008

[eluser]x386[/eluser]
Thanks Colin! What is this mod_rewrite and how to implement it? I googled it, but I didn't find anything interesting...


controller as a subdomain - El Forum - 10-15-2008

[eluser]Colin Williams[/eluser]
It's an Apache module that lets you rewrite URI requests. I'm not sure what Google you used Smile but my search for "mod_rewrite" returns the best resource I know of: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html


controller as a subdomain - El Forum - 10-15-2008

[eluser]Colin Williams[/eluser]
Also, the Router class is the ultimate controller in CI, so you could overload one or some of it's methods in your own MY_Router.php library and sniff out the subdomain before validating and routing the request


controller as a subdomain - El Forum - 10-15-2008

[eluser]John_Betong[/eluser]
[quote author="x386" date="1224079576"]Is this possible to access controllers not only by site.com/controller and have something like this: controller.site.com?
Thanks![/quote]
 
 
I use a sub-domain on this site http://iching.justjoolz.com and for me Smile it was not easy to setup.
 
In my http://localhost I have a path to c:/www/iching/index.php and online I have http://iching.justjoolz.com/index.php
 

index.php - common to both sites
Code:
...
   define('LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME']);
   ...
   ...
  $system_folder = "ci_system"; // Default - ver: 1.63
  if (LOCALHOST) {
    $system_folder = "../ci_system";
  }
  
  // http://iching.justjoolz.com
  if (strpos($_SERVER['SERVER_NAME'], 'justjoolz')) {
    $system_folder = "../ci_system"; // ver: 1.63
  }
  ...
  ...
  $application_folder = 'iching'; // http://iching.justjoolz.com/iching
  if (LOCALHOST) {
    $application_folder = '../iching';
  }

  // http://iching.johns-jokes.com
  if (strpos($_SERVER['SERVER_NAME'], 'jokes')) {
    $application_folder = 'http://iching.johns-jokes.com'; // online setting
  }
  // echo '$application_folder --> '  .$application_folder ; die;
  ...
  ...
 
Needless to say my config.php was setup with trial and error, if you want a copy let me know.