Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

site with www and without www is not acting same for baseurl in codeigniter

I have a site where I have added the base_url() for calling the css and js files. The base_url() is without www. It is working fine with http://example.com but not working with http://www.example.com. That is it is showing some issues like not taking the fonts, sessions etc. I have searched many solutions but not able to find the right one. Please tell me a solution.

like image 773
prasanth prem Avatar asked Dec 12 '25 16:12

prasanth prem


1 Answers

You can do using .htacess redirect as @Arjar Aung provided.
I used this way at my config file

    if(strpos($_SERVER['HTTP_HOST'],'www')===false)
    {
        $config['base_url'] = 'http://example.com';
    }
    else
    {
        $config['base_url'] = 'http://www.example.com';
    }
like image 82
Shaiful Islam Avatar answered Dec 15 '25 07:12

Shaiful Islam