Codeigniter - how to remove the index.php from url?

前端 未结 4 1989
醉酒成梦
醉酒成梦 2021-01-05 14:03

I have following structure of my project

/system
/applications
  /cache
  /core
  /helpers
  /hook
  /language
  /libraries
  /logs
  /third_party
  /admin-p         


        
相关标签:
4条回答
  • 2021-01-05 14:37

    Open config.php from system/application/config directory

    and replace

    $config['index_page'] = “index.php” by $config['index_page'] = “”

    Create a “.htaccess” file in the root of CodeIgniter directory

    and add the following lines.

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

    In some case the default setting for uri_protocol does not work properly.

    To solve this problem just replace

    `$config['uri_protocol'] = “AUTO”` 
    

    by

     $config['uri_protocol'] = “REQUEST_URI” 
    

    from system/application/config/config.php

    0 讨论(0)
  • 2021-01-05 14:39

    Have a look in the config.php file, there is a variable named 'index_page'

    try changing

    $config['index_page'] = "index.php";
    

    to

    $config['index_page'] = "";
    
    0 讨论(0)
  • 2021-01-05 14:44

    Be sure of the following :

    1. .htaccess needs to be placed in the same directory as the index.php file, usually root of the application.
    2. read the manual about codeigniter and .htaccess
    3. Be sure that apache is running the rewrite module named : rewrite_module you can read more about enabling the module on linux here : Blog post or for wamp here : Wamp icon -> Apache -> Apache Modules -> rewrite_module
    0 讨论(0)
  • 2021-01-05 14:59

    if your root folder for project is not root of domain i.e. your website is subdirectory of a domain http://localhost/myproject then you need an additional line in your .htaccess file that is RewriteBase

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

    Also make sure, your config.php is configured as

    $config['base_url'] = 'http://localhost/myproject/';
    $config['index_page'] = '';
    

    And mod_rewrite is enable in apache's config file.

    0 讨论(0)
提交回复
热议问题