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
base_url([$uri = ”[, $protocol = null]])
Define your base URL in your
.env
file at the root of your project. Example: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 addwww.
in front of localhost like thisapp.baseURL = 'http://www.yourdomain.com/'
Also Remember to change your
$baseURL
inappConfigApp.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