Codeigniter 4 Remove Public and Index.php From URL

Codeigniter 4 Remove Public and Index.php From URL

How to remove index.php in codeigniter. If you want to remove public and index.php from URL in Codeigniter 4 framework. So this tutorial will help you.

In this tutorial, we would love to share with you, how to remove public and index.php from URLs in the new Codeigniter 4 frameworks.

The directory structure of the New Codeigniter 4 framework has been changed.

How to remove public/index.php/ from URL in Codeigniter 4

Follow the below-given steps and easily remove the public and index.php from URL in Codeigniter 4 framework:

Step 1: Change in App.php File

The first step is to open the app.app file. And the changes mentioned below. You have to do this in your App.php file.

So go to project_name/app/Config/App.php and change mention below:

public $baseURL = 'http://localhost:8080';

To

public $baseURL = 'http://localhost/your_project_name/';

And the second change in the app.php file:

public $uriProtocol = 'REQUEST_URI';

To

public $uriProtocol = 'PATH_INFO';

Step 2: Copy index.php and .htaccess

Visit inside public directory. And copy index.php and .htaccess to codeigniter app root directory.

Step 3: Change In index.php

In the root project directory, open index.php and edit the following line:

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

 change TO

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

Conclusion

In this tutorial, you have learned how to remove the public and index.php in new Codeigniter 4 framework.

Now you can hit the below url in your browser.

example.com/hello

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

8 replies to Codeigniter 4 Remove Public and Index.php From URL

  1. Thank you so much now working fine.

  2. nice dear, i was found best solution thank you

  3. i know its work fine but how to use command line after this type of configuration.

  4. Gracias, me sirvio mucho este tutorail, gracias desde México

  5. its working fine thank you.

  6. Very nice post. I just stumbled upon your blog and wished
    to say that I have really enjoyed surfing around your blog posts.
    In any case I will be subscribing to your feed and I hope you write again soon!

  7. where we fine index.php file ?

    • inside public directory of your codeigniter app

Leave a Reply

Your email address will not be published. Required fields are marked *