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

Dharman
  • 30,962
  • 25
  • 85
  • 135
koool
  • 15,157
  • 11
  • 45
  • 60
  • 1
    Try checking out [this link](http://www.terencechang.com/2008/08/28/codeigniter-no-input-file-specified-php-5-apache-2/) and see if it fixes the problem. – Vap0r May 25 '11 at 02:02
  • No doesnt help thanks for the effort – koool May 25 '11 at 02:16

6 Answers6

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 !

Ali Mohamed
  • 3,186
  • 2
  • 14
  • 6
63

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

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

to

RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
Suresh Sekar
  • 928
  • 6
  • 7
  • 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 '14 at 01:38
  • Its getting me 404 page not found with CI 3 – Nipun Tyagi Aug 22 '16 at 05: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

koool
  • 15,157
  • 11
  • 45
  • 60
  • 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 '14 at 01: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!

Community
  • 1
  • 1
Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
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>
Winter MC
  • 355
  • 2
  • 7
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.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33178756) – ahuemmer Nov 19 '22 at 07:59