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

前端 未结 9 878
有刺的猬
有刺的猬 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:28

    I was able to "solve" the problem in my hostinger server in one project. After I created a new project with a newer version of codeigniter 4 I realized that I could no longer use the same solution and after hours of research I found a very simple solution.

    What I did is I changed the root directory to be the public folder using the .htaccess that is located at the root folder of the project.

    #RewriteEngine on
    #RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC,OR]
    #RewriteCond %{HTTP_HOST} ^mydomain.com$
    #RewriteCond %{REQUEST_URI} !public/
    #RewriteRule (.*) /public/$1 [L]
    

    Using that trick I could load my codeigniter 4 in a live server without any problem. Actually, I used this to configure a codeigniter 4 project inside a subdomain.

提交回复
热议问题