Remove index.php from URL in Codeigniter

前端 未结 7 724
北恋
北恋 2021-01-02 15:48

I have done this lots of time. But than also I am stuck here again (in a different server) and can not figure out what is the issue.

Completed htaccess editing

相关标签:
7条回答
  • 2021-01-02 15:50

    I wanted to contribute here as I was having trouble myself. I'm using IIS5.1 for development only (Highly not recommended!)

    1- Make sure that you config.php file has:

    $config['index_page'] = '';
    

    2- My app is not on the root folder, it's at localhost/CodeIgniter/. I updated config.php to:

    $config['base_url'] = 'http://localhost/CodeIgniter/';
    

    3- You need Mod-Rewrite capabilities. This is embedded with most servers, but IIS5.1 needs a separate tool. I used: IIS Mod-Rewrite by micronovae. It's free as long as you use it on localhost

    I put the following code (Instead of CodeIgniter, put the name of the folder):

    RewriteEngine on
    RewriteCond $0 !^/CodeIgniter/(css|js|swf|images|system|tools|themes|index\.php) [NC]
    RewriteRule ^/CodeIgniter/(.*)$ /CodeIgniter/index.php/$1 [L]
    

    If your application is at the root, the code you should use would be simply:

    RewriteEngine on
    RewriteCond $0 !^(css|js|swf|images|system|tools|themes|index\.php) [NC]
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    Hope it helps.

    0 讨论(0)
  • 2021-01-02 15:56

    First check whether your apache is supporting mod_rewrite. If yes then add a .htaccess file. My codeigniter .htaccess file is:

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

    Finally in your config file, change your base_url, remove index.php from that if you have added.

    0 讨论(0)
  • 2021-01-02 16:00

    This is the simple way and it works fine for removing index.php from your url

    RewriteEngine on
    RewriteCond $1 !^(index\.php|uploads|css|js|lib|img|bootstrap|robots\.txt)
    RewriteRule ^(.*)$ /manage/index.php/$1 [L]
    
    instead of manage put your own application folder name.
    
    0 讨论(0)
  • 2021-01-02 16:04
    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
    RewriteRule ^pages/.*$ http://localhost/test/? [R=301,L]
    
    0 讨论(0)
  • 2021-01-02 16:10

    Only three steps are require to remove index.php from url in Codeigniter in WAMP environment.

    1) Create .htacess file in parallel to application holder and just copy past the following code:

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

    2) Change $config['index_page'] to blank in config.php in application folder as below:

    $config['index_page'] = '';
    

    3) Enable “rewrite_module” of apache.

    Restart your apache and its done.

    Details : http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

    0 讨论(0)
  • 2021-01-02 16:12

    Though your client confirmed the rewrite module is working, what don't you confirm it yourself, make a php file on the root of the project with the code below and try to browse the file.

    <?php
     if( !function_exists('apache_get_modules')){
            echo 'Rewrite module not available';
     }else{
        if(in_array('mod_rewrite',apache_get_modules()))
            echo 'Rewrite module enabled';
     }
    
    0 讨论(0)
提交回复
热议问题