How to remove “index.php” in codeigniter's path

后端 未结 27 1353
盖世英雄少女心
盖世英雄少女心 2020-11-22 07:17

How do I remove the \"index.php\" sticking out in every path in codeigniter somewhere in the center? I want clean non index.php-fied URLs?

相关标签:
27条回答
  • 2020-11-22 07:57

    This one did me the complete magic:

    RewriteEngine on
    RewriteBase /
    # Hide the application and system directories by redirecting the request to index.php
    RewriteRule ^(application|system|\.svn) index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
    

    Hope it helps!

    0 讨论(0)
  • 2020-11-22 07:58

    If you are using Apache place a .htaccess file in your root web directory containing the following:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    Another good version is located here:

    http://snipplr.com/view/5966/codeigniter-htaccess/

    0 讨论(0)
  • 2020-11-22 07:58

    There are two way to solve index.php in url path for codeigniter

    1:In config/config.php Change code :

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

    to

    $config['index_page'] = '';
    

    2:Create .htacess in root path if not created,Copy the following code:-

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

    Save it and then check in your Apache Configuration rewrite_module OR mod_rewrite is Enabled.If not then please enabled. (Best Approach)!

    0 讨论(0)
  • 2020-11-22 07:58

    I use these lines in .htaccess file; which I place in root folder

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

    Then I can access http://example.com/controller/function/parameter

    instead of http://example.com/index.php/controller/function/parameter

    0 讨论(0)
  • 2020-11-22 07:58

    Step 1 :

    Add this in htaccess file

    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    #RewriteBase / 
    
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^ index.php [QSA,L] 
    </IfModule>
    

    Step 2 :

    Remove index.php in codeigniter config

    $config['base_url'] = ''; 
    $config['index_page'] = '';
    

    Step 3 :

    Allow overriding htaccess in Apache Configuration (Command)

    sudo nano /etc/apache2/apache2.conf and edit the file & change to

    AllowOverride All
    

    for www folder

    Step 4 :

    Enabled apache mod rewrite (Command)

    sudo a2enmod rewrite

    Step 5 :

    Restart Apache (Command)

    sudo /etc/init.d/apache2 restart
    
    0 讨论(0)
  • 2020-11-22 07:59

    Have a look in the system\application\config\config.php file, there is a variable named index_page

    It should look like this

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

    change it to

    $config['index_page'] = "";
    

    Then as mentioned you also need to add a rewrite rule to the .htaccess file

    Note: in CodeIgniter v2 this file was moved out of the system folder to application\config\config.php

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