Issues in removing index.php in CodeIgniter 3

前端 未结 10 1461
灰色年华
灰色年华 2021-01-13 06:53

I want to access my URL\'s without index.php in CodeIgniter. Here is my Blog controller

class Blog extends CI_Controller {

    pub         


        
10条回答
  •  情深已故
    2021-01-13 07:54

    Alright, i've been strugling with this for two days, and here is my solution for XAMPP and CodeIgniter 3

    Create new ".htaccess" file in root directory (not in CodeIgniter's application folder, where there's another htacces file, don't touch that one), with this inside:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    Then, find and change this values on config.php (CodeIgniter file, on config folder):

    $config['base_url']     = 'localhost/YourProject';
    $config['index_page']   = '';
    $config['uri_protocol'] = 'REQUEST_URI';
    

    Finally, on httpd.conf (Apache config file), find:

    #LoadModule rewrite_module modules/mod_rewrite.so

    and uncomment the line (remove #).


    That's it! Now

    localhost/myProject/news

    works as if I write

    localhost/myProject/index.php/news
    

提交回复
热议问题