CodeIgniter by default support only one application. I want multiple applications based on subdomain. So subdomain is the application folder name. If existed it should execute that else default. Here my requirement and logic goes…
Requirement:
http://dynamic.com applications/application (default)
http://appone.dynamic.com applicatons/appone
http://apptwo.dynamic.com applicatons/apptwo
.... ....
http://appx.dynamic.com applicatons/appx
when visitor type example URL like above, .htaccess or index.php should auto select which application folder to use.
I change codeIgniter default code in index.php and write this code which is working fine.
// multiple applications path //
$path = 'applications/';
// default folder //
$folder = 'application';
preg_match('/^(?<subdomain>\w+)\.(dynamic\.com)$/im', $_SERVER['HTTP_HOST'], $matches);
if (isset($matches['subdomain']) && is_dir($path . $matches['subdomain'])) {
$folder = strtolower($matches['subdomain']);
}
$application_folder = $path . $folder;
My question – Is it possible to write same logic in .htaccess? Is there any performance issue writing the code like mine in index.php? Suggest me or Help me on htaccess logic. Image also attached. Thank you!!

The way you’re doing it is correct. You’re setting the application folder that CodeIgniter will use in the index.php file.
Your only concern with performance would be your preg_match function and is_dir function. In my opinion, the string is rather small which shouldn’t be too much of a performance risk. I would however, write in a switch() statement so that they are more hard-coded so that you can avoid the is_dir function. By doing this method, you’d also switch to using if statements, which are extremely cheap instead of the preg_match function.
There’s not reason to write this in the .htaccess file, CodeIgniter gives you the ability to perform this. If you were to use this using .htaccess, you would need to have separate folders for install and start symlinking.