CodeIgniter removing index.php from url

前端 未结 30 1412
[愿得一人]
[愿得一人] 2020-11-21 11:51

My current urls look like this [mysite]index.php/[rest of the slug].
I want to strip index.php from these urls.

mod_rewrite

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 11:59

    Step:-1 Open the folder “application/config” and open the file “config.php“. find and replace the below code in config.php file.

    //find the below code   
    $config['index_page'] = "index.php" 
    //replace with the below code
    $config['index_page'] = ""
    

    Step:-2 Go to your CodeIgniter folder and create .htaccess

    Path:
    Your_website_folder/
    application/
    assets/
    system/
    .htaccess <——— this file
    index.php
    

    Step:-3 Write below code in .htaccess file

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

    Step:-4 In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php“, then find and replace the below code

    //Not needed for CodeIgniter 3 its already there.
    //find the below code
    $config['uri_protocol'] = "AUTO"
    //replace with the below code
    $config['uri_protocol'] = "REQUEST_URI" 
    

    Thats all but in wamp server it does not work because rewrite_module by default disabled so we have need to enable it. for this do the following

    1. Left click WAMP icon
    2. Apache
    3. Apache Modules
    4. Left click rewrite_module

    Original Documentation

    Example Link

提交回复
热议问题