CodeIgniter 3 cannot reliably infer every development URL from server variables. Set the local origin explicitly, including the port, keep index.php as the index page when rewriting is unavailable, and use site_url() for controller routes.
Last updated: November 2, 2026.
<?php
// application/config/config.php
$config['base_url'] = 'http://localhost:8000/';
$config['index_page'] = 'index.php';
// Application route: includes index.php
echo site_url('products/create');
// Static asset: does not include index.php
echo base_url('assets/css/app.css');This produces http://localhost:8000/index.php/products/create for the route and http://localhost:8000/assets/css/app.css for the stylesheet. The distinction is intentional.
Use the URL helper that matches the resource
The official CodeIgniter 3 URL Helper documentation says site_url() appends the configured index page, while base_url() does not. Use site_url() for controllers and application routes. Reserve base_url() for images, stylesheets, scripts, and other public files.
Do not concatenate the host, port, and index.php in view files. A single environment-specific configuration value makes links consistent and prevents accidental production URLs in local development. Keep separate development and production configuration values instead of deriving the public origin from an untrusted request Host header.
Start the development server from the correct directory
Run the server from the directory containing the front controller, or set the document root deliberately. The PHP built-in server documentation shows php -S localhost:8000 for development and warns that the server is not intended for public networks or production traffic.
After starting it, open the configured base URL and inspect one generated route before testing forms or redirects. Check links, redirects, form actions, and pagination because all of them may use the URL helper independently. If clean URLs are required, add a router script or use Apache or Nginx rewriting; do not set index_page to an empty string unless requests can actually reach the front controller.
Continue with reading the current PHP URL, building URLs safely, and configuring PHP.