Codeigniter 4 - Hide / Remove public folder and index.php from URL | 2my4edge

09 February 2022

Codeigniter 4 - Hide / Remove public folder and index.php from URL

Hide or Remove the public folder and index.php from codeigniter 4 URL is very simple, for that need to add some codes and we need to modify the folder structure. let me explain the detailed procedure the change the folder structure to remove public folder in codeigniter 4 URL with Windows XAMPP.

Hide / Remove public folder and index.php from URL

STEP 1 : Need Define BASEURL

In my previous Tutorial i have given the steps for installation, after that we need to define baseurl

PROJECT FOLDER -> ci4 -> app -> App.php

.../htdocs/ci4/app/App.php
public $baseURL = 'http://localhost/ci4/';

After that $uriProtocol we need change
find this line
public $uriProtocol = 'REQUEST_URI';

Replace it with

public $uriProtocol = 'PATH_INFO';

STEP  2: Copy the index.php and .htaccess file from public folder

index.php file and .htaccess file, we need to copy that two files from public folder and we need to paste it the project root path.

Hide / Remove public folder and index.php from URL foolder structure

STEP 3 : Modify index.php file.

Find this line
$pathsConfig = FCPATH . '../app/Config/Paths.php';
Replace the code with
$pathsConfig = FCPATH . 'app/Config/Paths.php';

That's all, now you can access you project with out public folder and index.php. 


STEP 4 : Apache conf file. (Rare case)

Even then, it is not working means, change some code in xampp apache (httpd.conf) file.

 <Directory "E:/xampp/cgi-bin">
    AllowOverride All
    Options None
    Require all granted
</Directory>

In the above code, AllowOverride All is there so no need to change anything. it will work smooth. if it was None, you need to change it to All


That's it, Now it will work smooth. if you have any doubts, comment below, i hope this tutorial is really helpful for you. stay connected for more tutorial like this.

No comments:

Post a Comment

^