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

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of site with www and without www is not acting same for baseurl in codeigniter without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.

Answer

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';
    }
We are here to answer your question about site with www and without www is not acting same for baseurl in codeigniter - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji