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

前端 未结 9 903
有刺的猬
有刺的猬 2021-02-02 18:00

I want normal URL like www.sample.com/controller not www.sample.com/public/index.php/controller.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCo         


        
9条回答
  •  长发绾君心
    2021-02-02 18:21

    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. remove index.php from url Codeigniter.

    So go to project_name/app/Config/App.php and change mention below: How To Remove Public/index.php/ From URL In Codeigniter 4

    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

    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';
    

    We can also remove index.php in Codeigniter using .htaccess. I have given the example below.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

提交回复
热议问题