skip to Main Content

In Codeigniter 4 URL with www. not shown www in base URL().

$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");

$config['base_url'] .= "://". $_SERVER['HTTP_HOST'];

$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);

This source code is also not working.

How can I solve this?

2

Answers


  1. base_url([$uri = ”[, $protocol = null]])

    Returns your site base URL, as specified in your config file. Example:

    <?php
    
    echo base_url();
    

    Define your base URL in your .env file at the root of your project. Example:

    app.baseURL = 'http://www.your-domain.com'
    
    Login or Signup to reply.
  2. when you first setup a codeigniter project you will see a env file in your root, copy that file and rename it to .env env with a dot.

    Then in that folder look at line 23 I think or just look for #app.baseURL = 'http://localhost:8080/' Then Remove the hash(#) and just add www. in front of localhost like this app.baseURL = 'http://www.yourdomain.com/'

    Also Remember to change your $baseURL in appConfigApp.php to your domain.

    FYI:

    What is a .env file?
    A .env file or dotenv file is a simple text configuration file for controlling your Applications environment constants.

    I recommend you look at the codeignter official docs aswell

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search