🌐 Setting up Base URL in CodeIgniter
The base URL is the root URL of your CodeIgniter application. It is required for generating correct links and loading assets like CSS, JS, and images. You can configure it in the App.php config file or use the .env file for dynamic environments.
🔧 Method 1: Set in app/Config/App.php
Open the file app/Config/App.php and set the $baseURL property:
public string $baseURL = 'http://localhost/myapp/';
Replace myapp with your actual project folder name.
📁 Method 2: Use .env File (Recommended for Environments)
- Rename the file
env(in project root) to.env - Uncomment and set the base URL like this:
app.baseURL = 'http://localhost/myapp/'
Using .env allows different base URLs for local, staging, and production environments without changing code.
✅ Tips
- 🔄 Always end the URL with a trailing slash
/. - 🌐 Use
base_url()function in views to generate links and load assets. - ⚠️ Incorrect base URL may result in broken links or missing assets.


