ci4
1<?php
2
3declare(strict_types=1);
4
5/**
6* This file is part of CodeIgniter 4 framework.
7*
8* (c) CodeIgniter Foundation <admin@codeigniter.com>
9*
10* For the full copyright and license information, please view
11* the LICENSE file that was distributed with this source code.
12*/
13
14/*
15* CodeIgniter PHP-Development Server Rewrite Rules
16*
17* This script works with the CLI serve command to help run a seamless
18* development server based around PHP's built-in development
19* server. This file simply tries to mimic Apache's mod_rewrite
20* functionality so the site will operate as normal.
21*/
22
23// @codeCoverageIgnoreStart
24$uri = urldecode(
25parse_url('https://codeigniter.com' . $_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? ''
26);
27
28// All request handle by index.php file.
29$_SERVER['SCRIPT_NAME'] = '/index.php';
30
31// Full path
32$path = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . ltrim($uri, '/');
33
34// If $path is an existing file or folder within the public folder
35// then let the request handle it like normal.
36if ($uri !== '/' && (is_file($path) || is_dir($path))) {
37return false;
38}
39
40unset($uri, $path);
41
42// Otherwise, we'll load the index file and let
43// the framework handle the request from here.
44require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'index.php';
45// @codeCoverageIgnoreEnd
46