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, :)

6
  • stackoverflow.com/questions/19183311/… Commented Jan 22, 2020 at 13:08
  • Does this answer your question? CodeIgniter removing index.php from url Commented Jan 22, 2020 at 13:09
  • I try all this answer but any success :( Commented Jan 22, 2020 at 13:20
  • Check it $config['uri_protocol'] = "REQUEST_URI"; Commented Jan 22, 2020 at 13:22
  • @Dmitry Why set this to "REQUEST_URI"? The OP appears to be using PATH_INFO? Commented Jan 25, 2020 at 1:17

8 Answers 8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

"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?
1

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

Comments

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

Comments

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';

Comments

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.

Comments

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!

Comments

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>

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.