Blog Codeigniter Remove Public From URL in Codeigniter 4

Remove Public From URL in Codeigniter 4

Codeigniter 4 is the latest version of Codeigniter. If you are building a web application with Codeigniter, you can’t find any index.php file in the root directory. Instead of you need an access controller through yourwebsite.com/public/controller. In the latest version of Codeigniter changed the directory structure. While you building a professional application with Codeigniter, You need to remove the public from the URL for making clean URL. So this tutorial will help you to remove public from URL in Codeigniter 4.

How to remove index.php from URL in CodeIgniter?

Step 1: Copy Index.php and htaccess File from Public

In Codeigniter 4 you can’t find any index.php and htaccess file in root directory. That’s why root directory remains open. At first, Go to the public directory. Copy index.php and .htaccess file. Then paste it to codeigniter root directory.

Copy index.php and htaccess file

Step 2: Edit Index.php File in Root Directory

Now go to Codeigniter 4 root directory. Edit index.php with code editor and change the following line.

$pathsPath = realpath(FCPATH . '../app/Config/Paths.php');

To

$pathsPath = realpath(FCPATH . '/app/Config/Paths.php');

That’s it. Now try access your controller without public in URL. An Example:

Old URL: http://example.com/public/blog

To

New URL: http://example/blog

Conclusion

I hope you successfully removed public URL in your Codeigniter 4 Project. If you have any question about codeigniter, Please comment below.

Moin Uddinhttps://webcods.com
I am a Web Developer, Entrepreneur, and Owner of Webcods.com. I love coding and create amazing content about programming. If you need any help on web development, contact me on Facebook.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular