Issues in removing index.php in CodeIgniter 3

前端 未结 10 1370
灰色年华
灰色年华 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:44

    To remove index.php create a .htaccess file in the same folder as your site’s main index.php file.
    Then add the following code to this newly created .htaccess file:

    
        RewriteEngine On
        RewriteBase /
    
        # Removes index.php from ExpressionEngine URLs
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/system/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    
        # Directs all EE web requests through the site index file
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
    
    

    this code have two parts
    1 - remove index.php
    2 - redirect all site requests to the index file.

提交回复
热议问题