4

I try to remove the index page in Codeigniter

the first step I do this //old Code

$config['index_page'] = "index.php”

//New updated code(Only Need to remove index.php )

$config['index_page'] = ""

then for second step i do this creat file .htaccess in root of codigniter then put this code source

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

but it's the same problem and I can't refresh the web page

with index page the URL work: http://localhost:8089/codeigniter3/index.php/Hello/dispdata but without index page don't work http://localhost:8089/codeigniter3/Hello/dispdata

Hello is the controller, finally thank for help, :)

Bhadresh Kathiriya
  • 3,147
  • 2
  • 21
  • 41
JEEdz
  • 77
  • 1
  • 4

8 Answers8

4

The problem is, you installed it in /codeigniter3/

This should fix it:

// remove index.php
$config['index_page'] = ""

// Allow installation in a subfolder of your webroot
$config['uri_protocol'] = "REQUEST_URI"

And keep your rewrite settings, they are ok.

nito
  • 1,157
  • 8
  • 21
  • "The problem is, you installed it in `/codeigniter/`" - the "root of codeigniter" would seem to be `/codeigniter3/`. But why would this be "the problem"? If you change the `uri_protocol` setting to `REQUEST_URI` then won't it (incorrectly) include `/codeigniter3` as part of the routing? – MrWhite Jan 25 '20 at 00:55
1

Codeigniter url routing should come to your rescue. Refer: https://codeigniter.com/user_guide/general/routing.html

1
  1. Create a new File In Main Folder Named as (.htaccess) and paste this code in .htaccess file.

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /Enter your folder name/
    
  2. 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

  1. Rename 'application' to your applications folder name.

     RewriteCond %{REQUEST_URI} ^application.*
     RewriteRule ^(.*)$ /index.php?/$1 [L]
    

Checks to

 Rewrite Cond %{ENV:REDIRECT_STATUS} ^$    
 Rewrite Cond %{REQUEST_FILENAME} !-f    
 Rewrite Cond %{REQUEST_FILENAME} !-d    
 RewriteRule ^(.*)$ index.php?/$1 [L]    
</IfModule>

ErrorDocument 404 /index.php

Premlatha
  • 1,676
  • 2
  • 20
  • 40
0

try this

RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite

And then do this

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

$config['uri_protocol'] = 'REQUEST_URI';
0

Can you try the below code in your .htaccess file on root folder

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Shawn
  • 1,232
  • 1
  • 14
  • 44
ashokan
  • 70
  • 5
0

Please follow the below process:

  1. Create .htaccess file in the project root folder
  2. Check whether mod_rewrite is enable on server?

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

This will resolve your issue. Let me know if you are still facing issue.

Ronak Chauhan
  • 681
  • 1
  • 8
  • 22
0

Try this step:

  1. remove index.php from $config['index_page'] = "index.php"
  2. create .htaccess in the project root folder like below code

    RewriteEngine on
    RewriteBase /codeigniter3/
    RewriteCond $1 !^(index\.php|css|fonts|images|js)
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    Then try http://localhost:8089/codeigniter3/Hello/dispdata

I hope it will fix your problem!

Shawn
  • 1,232
  • 1
  • 14
  • 44
0
RewriteRule ^(.*)$ index.php/$1 [L]

Since you are passing the correct URL-path as additional pathname information (path_info) in your .htaccess directive then try explicitly setting this in the config:

$config['uri_protocol'] = 'path_info';

Unless this is set explicitly then it will try various methods, which may be failing since you have now removed index.php from the URL.

MrWhite
  • 43,179
  • 8
  • 60
  • 84