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

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

    have you tried this:

        RewriteEngine On
        RewriteBase /yoursite.com/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ public/index.php/$1 [L]
    
    0 讨论(0)
  • 2021-02-02 18:35

    I've no idea how you get this .htaccess. If you download CodeIgniter 4 from here and you can see Htaccess file is different what you added.

    Since there are many changes in CodeIgniter (1,2,3) to Codeigniter 4, htaccess moved to public/ folder which will set to document root and .htaccess which place outside will not valid in CI 4


    Correct path to .htaccess

    public/.htaccess
    

    Note: I just tested index.php URL issue and there was no issue like that. worked/loaded fine without index.php

    0 讨论(0)
  • 2021-02-02 18:47

    create a .htaccess file in /public with :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    0 讨论(0)
提交回复
热议问题