Issues in removing index.php in CodeIgniter 3

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

    Enable mod_rewrite restart your apache server and in your .htaccess

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    
    0 讨论(0)
  • 2021-01-13 07:35

    I just now struggled with this part again, even after being used to Codeigniter for 2+ years.

    None of the answers helped me exactly, including the official Codeigniter's page about this, so I'm posting the solution that worked for me.

    1. Enable Rewrite engine

      sudo a2enmod rewrite
      
    2. Change Apache's config file to allow folders to allow overriding of default security setting

      sudo nano /etc/apache2/apache2.conf
      

    Under the "Directory" options depending on the location of your files, edit

        AllowOverride None
    

    to

        AllowOverride All
    

    e.g.: My server files are in "/var/www", so my final result for corresponding Directory options is:

        <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    
    1. Create a ".htaccess" file in the root of your Codeigniter project, i.e.: along with where applications, system folders exist.

    In the file, put the following:

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

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

    to

        $config['index_page'] = '';
    
    1. Restart apache2:

      sudo service apache2 restart
      

    Enjoy!

    0 讨论(0)
  • 2021-01-13 07:37

    Please change your base_url path which exist in application/config

    $config['base_url'] ='localhost/projectname/index.php' 
    

    to

    $config['base_url'] ='localhost/projectname/' 
    
    0 讨论(0)
  • 2021-01-13 07:38

    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 Write below code in .htaccess file

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

    Step:-3 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

    //find the below code
    $config['uri_protocol'] = "AUTO"
    //replace with the below code
    $config['uri_protocol'] = "REQUEST_URI" 
    
    0 讨论(0)
  • 2021-01-13 07:40

    My Codeigniter version is 3.1.11 I'm trying all types of code in htaccess but that does not work then I was found this code.

    Place the .htaccess file in the project folder like this: htdocs/your_project/.htaccess Try this new code for .htaccess:

    RewriteEngine on 
    RewriteBase /your-project-directory-name/ 
    RewriteCond $1 !^(index.php|resources|robots.txt) 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    
    0 讨论(0)
  • 2021-01-13 07:43

    How to removed index.php from url has been asked so many times, It is the same as what is for codeigniter 2 and 3.

    For Xampp With Codeigniter Windows

    Find application/config/config.php

    Replace This

    $config['base_url'] = "";

    With This

    $config['base_url'] = "your-project-url";

    Replace This

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

    With This

    $config['index_page'] = ""

    In main directory create file called .htaccess

    I use code below works fine for me in xampp in windows. More htacces here

    Options +FollowSymLinks
    Options -Indexes
    
    <FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
        Order deny,allow
        Deny from all
    </FilesMatch>
    
    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    Note: make sure your controllers are like example Welcome.php instead of welcome.php also you might need to create new routes in your route.php if remove index.php

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