88

I am a beginner in Codeigniter and I saw a CI tutorial and was just trying to do a simple thing. I downloaded the CI and added this file to controller directory, but it won't work.

<?php

class site extends CI_Controller
{
    public function index()
    {
        echo "Hello World";
    }

    function dosomething()
    {
        echo "Do Something";
    }   
}    
?>

When I try to access it using http://..../index.php/site I get the output ... "no input file specified" .... by the way, I named the file site.php

2
  • 1
    Try checking out this link and see if it fixes the problem.
    – Vap0r
    May 25, 2011 at 2:02
  • No doesnt help thanks for the effort
    – koool
    May 25, 2011 at 2:16

6 Answers 6

307

Just add the ? sign after index.php in the .htaccess file :

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

and it would work !

8
  • For me this serves a 301 redirect and I end up with /?/ in the URL.
    – Ade
    Oct 20, 2013 at 9:55
  • @Ali Mohamed, which of the htaccess file do you add this line? I tried but does not have any effect
    – Bahdeng
    Jan 4, 2014 at 12:40
  • 1
    @Bahdeng you need to place this snippet in .htaccess file in your project directory. Jan 10, 2014 at 20:19
  • change above line according to your application directory like if you application is not on root directory , write following code in place of above line RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
    – skovy
    Oct 22, 2014 at 1:39
  • 1
    @NSGodMode that would be in codeigniter root directory besides index.php Mar 15, 2015 at 8:10
63

Godaddy hosting it seems fixed on .htaccess, myself it is working

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

to

RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
2
  • change above line according to your application directory like if you application is not on root directory , write following code in place of above line RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
    – skovy
    Oct 22, 2014 at 1:38
  • Its getting me 404 page not found with CI 3 Aug 22, 2016 at 5:14
38

I found the answer to this question here..... The problem was hosting server... I thank all who tried .... Hope this will help others

Godaddy Installation Tips

1
  • change above line according to your application directory like if you application is not on root directory , write following code in place of above line RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
    – skovy
    Oct 22, 2014 at 1:39
18

RewriteEngine, DirectoryIndex in .htaccess file of CodeIgniter apps

I just changed the .htaccess file contents and as shown in the following links answer. And tried refreshing the page (which didn't work, and couldn't find the request to my controller) it worked.

Then just because of my doubt I undone the changes I did to my .htaccess inside my public_html folder back to original .htaccess content. So it's now as follows (which is originally it was):

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]

And now also it works.

Hint: Seems like before the Rewrite Rules haven't been clearly setup within the Server context.

My file structure is as follows:

/
|- gheapp
|    |- application
|    L- system
|
|- public_html
|    |- .htaccess
|    L- index.php

And in the index.php I have set up the following paths to the system and the application:

$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';

Note: by doing so, our application source code becomes hidden to the public at first.

Please, if you guys find anything wrong with my answer, comment and re-correct me!
Hope beginners would find this answer helpful.

Thanks!

0
1

My site is hosted on MochaHost, i had a tough time to setup the .htaccess file so that i can remove the index.php from my urls. However, after some googling, i combined the answer on this thread and other answers. My final working .htaccess file has the following contents:

<IfModule mod_rewrite.c>
    # Turn on URL rewriting
    RewriteEngine On

    # If your website begins from a folder e.g localhost/my_project then 
    # you have to change it to: RewriteBase /my_project/
    # If your site begins from the root e.g. example.local/ then
    # let it as it is
    RewriteBase /

    # Protect application and system files from being viewed when the index.php is missing
    RewriteCond $1 ^(application|system|private|logs)

    # Rewrite to index.php/access_denied/URL
    RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

    # Allow these directories and files to be displayed directly:
    RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|app_upload|assets|css|js|images)

    # No rewriting
    RewriteRule ^(.*)$ - [PT,L]

    # Rewrite to index.php/URL
    RewriteRule ^(.*)$ index.php?/$1 [PT,L]
</IfModule>
1
  • 1
    This solved my problem and got my site working as of October 2021. Thanks! Oct 13, 2021 at 16:01
0

One of my Codeigniter apps started returning this error after i restarted my server. When I checked the Codeigniter error log it says something like: "...[error] 879#0: *273 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/pathToWebsiteRootFolder/index.php) is not within the allowed path(s): ". So I added this: open_basedir= /pathToWebsiteRootFolder/index.php:

To a user.ini file I created in my website root folder.

And this Solved it.

FYI: Im using an NGINX web server.

However, Its strange because I didn't have to do this for the other Apps on the same server.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.