Search code examples
php.htaccesscodeigniterinstallationsubdomain

Subdomain does not work for CodeIgniter


I've a Subdomain under a maindomain. I want to install CodeIgniter under subdomain. But subdomain does not work for CodeIgniter default route.

Like my subdomain is demo.example.com not working. Normally core php is working for this subdomain but CodeIgniter not.

But when I call demo.example.com/welcome then working. Here welcome is a Controller name.

Can anyone help me what is my wrong ?

My Base URL is:

$config['base_url'] = 'http://demo.example.com';

My .htaccess is

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

My default controller(welcome.php) is

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
echo 'Welcome Subdomain';
}
}

Solution

  • Your controller name is Welcome.php as a public_html/demo/application/controllers/Welcome.php.

    Please change instead Welcome.php to welcome.php

    Set instead $route['default_controller'] = "Welcome" to $route['default_controller'] = "welcome" in routes.php