douzhen9428 2016-02-05 03:50
浏览 235
已采纳

CodeIgniter从url中删除index.php

I know this question has been asked a number of times. However, I still wasn't able to get rid of index.php url. It is preventing me to access my controller directly.

I am current using CodeIgniter 2.2.2.
And the following is my .htaccess file:

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

application/config:

//  Find the below code

$config['uri_protocol'] = "AUTO"

//  Replace it as

$config['uri_protocol'] = "REQUEST_URI" 

Any Idea? Thanks in advance for your time.

  • 写回答

8条回答 默认 最新

  • dongxin8392 2016-02-15 07:54
    关注

    Finally fixed my problem. I would like to share my answer to all of you. I am currently using a mac, my rename my .htaccess file into htaccess.txt And had the following code inside htaccess: RewriteEngine On

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    #RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
    ErrorDocument 404 /index.php
    

    Then make sure Apache is reading the htaccess.txt file by doing this:

    1. Uncomment the following line on your httpd.conf

    2. Go inside to the extra/httpd-default.conf file and change this line of code: AccessFileName .htaccess to AccessFileName htaccess.txt

    3. Restart Apache server

    4. Inside your config, make sure to leave 'base_url' empty (index page can still be there, doesn't matter). And $config['uri_protocol'] = 'REQUEST_URI';

    Hope this can help others out there!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?