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

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

    I have tried many solutions but the one i came up with is this:

    DirectoryIndex index.php
    RewriteEngine on
    
    RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots  \.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
    

    This iwill remove the index.php from the url as required.

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

    Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)

    And Add the following rules to .htaccess file,

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

    Then find the following line in your application/config/config.php file

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

    Set the variable empty as below.

    $config['index_page'] = '';
    

    That's it, it worked for me.

    If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one

    $config['uri_protocol'] = 'AUTO';
    
    0 讨论(0)
  • 2020-11-22 08:01

    This is an .htaccess for one of my CI projects:

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

    The last line should give you what you need, though you may or may not need '/projectFolder' depending on how your folder structure is set up. Good luck!

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

    Look in the \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 like this:

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

    It work for me, hope you too.

    0 讨论(0)
  • 2020-11-22 08:05
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /Foldername of your ci/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    
    0 讨论(0)
  • 2020-11-22 08:07

    Perfect solution [ tested on localhost as well as on real domain ]

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    
    0 讨论(0)
提交回复
热议问题