Remove index.php in codeigniter 2.1.0

前端 未结 9 1735
渐次进展
渐次进展 2020-11-29 05:10

I tried everything on google related to removing index.php from URL in codeigniter but no solution worked for me I am using codeigniter version 2.1.0 How I can remove index

相关标签:
9条回答
  • 2020-11-29 05:20

    i tested this on apache2 on many different hosting and it works great.

    use this htaccess

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

    be sure you have enabled mod_rewirte with a phpinfo();

    then do this in config/config.php:

    $config['index_page']   = '';
    |
    | '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'] = 'AUTO';
    

    if it doesn't works yet, try to change the $config['uri_protocol']='AUTO' to one of the listed inside application/config/config.php file on line 40/54:

    sometimes i used : REQUEST_URI instead of AUTO or "QUERY_STRING" for goDaddy hostings

    0 讨论(0)
  • 2020-11-29 05:22

    check your httpd.conf file

    change

    AllowOverride None
    

    to

    AllowOverride All
    
    0 讨论(0)
  • 2020-11-29 05:25

    You just need to create .htaccess file in project folder and write: RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Rewrite all other URLs to index.php/URL
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 
    
    </IfModule>
    <IfModule !mod_rewrite.c>
     ErrorDocument 404 index.php
     </IfModule>
    
     And You don't need to define in base_url in config file:
     $config['base_url'] = '';// blank it.
    
     I hope it will work perfectly ...
    
    0 讨论(0)
  • 2020-11-29 05:28

    For me, Raphael Caixetas solution didn't work, but this did :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    
    0 讨论(0)
  • 2020-11-29 05:28

    Have you tried using the example given in the CodeIgniter user guide?

    By default, the index.php file will be included in your URLs:

    example.com/index.php/news/article/my_article
    

    You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.

    http://codeigniter.com/user_guide/general/urls.html

    0 讨论(0)
  • 2020-11-29 05:30

    In addition of the .htaccess file given by Robert Stanley (see his answer), go to application/config/config.php, look for $config['index_page'] = "index.php"; and replace it with $config['index_page'] = "";

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