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

后端 未结 27 1443
盖世英雄少女心
盖世英雄少女心 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 08:08

    I had some big issues with removing the index.php. As a general rule the .htaccess below has been tested on several servers and generally works:

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

    If you don't have any luck with that then the next step is to adjust your config file. Try some of the other URI protocols e.g.

    | 'AUTO'            Default - auto detects
    | 'PATH_INFO'       Uses the PATH_INFO
    | 'QUERY_STRING'    Uses the QUERY_STRING
    | 'REQUEST_URI'     Uses the REQUEST_URI
    | 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
    
       $config['uri_protocol']  = 'ORIG_PATH_INFO';
    

    If your still not having any luck try changing the rewrite rule to include your subfolder. This is often a problem if your using a temporary URL on a dev server etc:

    RewriteRule ^(.*)$ /subofolder1/subfolder2/index.php/$1 [L]  
    

    Just play around with these options, one should work. Also, make sure your index file is set to:

    $config['index_page'] = '';
    

    Good luck!

    0 讨论(0)
  • 2020-11-22 08:09
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    

    This must definitely work.. have a try

    0 讨论(0)
  • 2020-11-22 08:09

    Ensure you have enabled mod_rewrite (I hadn't).
    To enable:

    sudo a2enmod rewrite  
    

    Also, replace AllowOverride None by AllowOverride All

    sudo gedit /etc/apache2/sites-available/default  
    

    Finaly...

    sudo /etc/init.d/apache2 restart  
    

    My .htaccess is

    RewriteEngine on  
    RewriteCond $1 !^(index\.php|[assets/css/js/img]|robots\.txt)  
    RewriteRule ^(.*)$ index.php/$1 [L]  
    
    0 讨论(0)
  • 2020-11-22 08:09

    If you are on linux and using apache2 server then we may need to override apache2.conf file also beside changes on .htaccess file. Find apache2 configuration file on /etc/apache2/apache2.conf .

    Search Directory /var/www/ Change AllowOverride None -> AllowOverride All

    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory
    
    0 讨论(0)
  • 2020-11-22 08:10

    Use mod_rewrite as instructed in this tutorial from the CI wiki.

    0 讨论(0)
  • 2020-11-22 08:11

    Just thought i might add

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

    would be the .htaccess and be sure to edit your application/config.php variable in the following manner:

    replace

    $config['uri_protocol'] = “AUTO” 
    

    with

    $config['uri_protocol'] = “REQUEST_URI”
    
    0 讨论(0)
提交回复
热议问题