44

Can someone help me with this? I'm feeling like I've been hitting my head against a wall for over 2 hrs now.

I've got Apache 2.2.8 + PHP 5.2.6 installed on my machine and the .htaccess with the code below works fine, no errors.

RewriteEngine on
RewriteCond $1 !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

The same code on my hosting provider server gives me a 404 error code and outputs only: No input file specified. index.php is there. I know they have Apache installed (cannot find version info anywhere) and they're running PHP v5.2.8.

I'm on Windows XP 64-bit, they're running some Linux with PHP in CGI/FastCGI mode. Can anyone suggest what could be the problem?

PS. if that's important that's for CodeIgniter to work with friendly URLs.


Update1:

mod_rewrite is installed and on.

What I've noticed is that if I change in RewriteRule to /index.php?$1 (question mark instead of forward slash) it goes into an infinite loop. Anyway, using question mark isn't an option as CodeIgniter (required) is not going to work this way.

Homepage also works when I request index.php directly: example.com/index.php

I'm starting to think it might be apache thinking that once the trailing slash is added it is not a file anymore but a folder. how to change such a behaviour?


Update 2:

I was wrong.
Apache handles these URLs correctly.
Requesting http://example.com/index.php/start/ (homepage) or any other valid address works.
Seems that Apache is just not forwarding the query for some reason.


Update 3:

Just to be clear what I'm trying to achieve.
I want to rewrite addresses like that:

http://www.example.com/something/ => http://www.example.com/index.php/something/ http://www.example.com/something/else/ => http://www.example.com/index.php/something/else/

7
  • Try some debugging with mod_rewrite’s logging feature (see RewriteLogLevel directive).
    – Gumbo
    Oct 12, 2009 at 22:27
  • Upload a PHP file with the text: <?php phpinfo(); ?> - accessing that file will print out all of the server settings including Apache version and possibly a list of Apache modules. You'll need to ensure mod_rewrite is installed in order to use these features.
    – pix0r
    Oct 12, 2009 at 22:27
  • tried that. apache version is stripped out from there.
    – Michal M
    Oct 12, 2009 at 22:30
  • I'm not sure I understand what your problem is, exactly. Is it all working now? What urls are you trying to rewrite to / from?
    – Tom Leys
    Oct 13, 2009 at 1:36
  • No, not working. Question updated.
    – Michal M
    Oct 13, 2009 at 7:27

16 Answers 16

92

I was beating my head up against this as well. I'm also installing Code Igniter.

The goocher was no RewriteBase. Here's my .htaccess:

DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)

RewriteRule ^(.*)$ index.php?/$1 [L]
3
  • Just a notice to your code: robots\.txt part is not needed, because of this RewriteCond %{REQUEST_FILENAME} !-f Apr 30, 2013 at 11:05
  • 2
    I already had a RewriteBase, but what fixed it for me was the ? after index.php on the last RewriteRule. This was on a Plesk panel based server running apache/php over fastcgi. May 5, 2015 at 18:06
  • 1
    but it create problem with this function basename=$_SERVER['PHP_SELF']; which returns only index.php
    – Vicky
    Sep 15, 2015 at 10:52
28

The Problem

I encountered a similar problem just now and unfortunately none of the answers in this thread helped:

Zend Framework was giving out "No input file specified.", but:

  • The default RewriteBase was just fine, and adding RewriteBase / did not help
  • It's a shared hosting server and only FastCGI is available (no ability to switch to SuPHP)
  • AcceptPathInfo was on
  • There was no problem with URL rewriting in general on the server

So the answer came from the following site: https://ellislab.com/forums/viewthread/55620/P15 [dead link] (even though the host is not DreamHost).

The Solution

Apparently all you need to do is replace this line:

RewriteRule ^(.*)$ index.php/$1

With this:

RewriteRule ^(.*)$ index.php?/$1

Problem solved.

3
  • 1
    another problem you have created if you are using this function basename=$_SERVER['PHP_SELF']; which return only index.php
    – Vicky
    Sep 15, 2015 at 10:54
  • I don't know why, but this worked perfectly for me :)
    – Danon
    Mar 16, 2017 at 13:14
  • Question mark fixed it for me with getting my site to work on ISPConfig.
    – Gladen
    Apr 28, 2018 at 11:36
9

This worked for me:

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

After index.php, the question mark is important!

0
4

Try if it works with a simpler RewriteCond; like one that rewrites only everything that isn't an existing file/folder/link:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ /index.php/$1 [R,L]
2
  • this works for the homepage: example.com/, not for anything else like example.com/something/
    – Michal M
    Oct 13, 2009 at 8:00
  • Oh, now I get it... you want to REDIRECT the requests instead of just REWRITING... (if I understood your update #3 correctly :) Try adding [R] into the end of the rewriterule, see my updated answer.
    – kkyy
    Oct 13, 2009 at 8:12
3

mod_rewrite is a bit too smart for its own good, because it tries to figure out what sort of redirect it should be doing. In this case it looks to mod_rewrite like you're trying to redirect to a folder, so it looks for the folder and can't find it, hence the error.

Edit: Just to be perfectly clear I think your best bet is to change your rewrite rule to:

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

unless there is a very speciic reason why you want it to be a forward slash.

Edit 2: I see that you already tried this. The reason you're getting an infinite loop is because you have index.php in your rewrite condition. If you remove that you should be free of the infinite loop.

1
  • using ? mark isn't an option. CodeIgniter won't work this way.
    – Michal M
    Oct 13, 2009 at 7:51
3

Go Daddy Users:

  1. login to your Go Daddy Account
  2. click on your hosting account.
  3. go to Settings > File Extensions Management
  4. change .php and .php5 to run under PHP5.2X (instead of PHP5.2xFastCGI)

SOLVED!!!!

2

this code will fixed this issue.

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

.htaccess for Live Server :-

DirectoryIndex index.php

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)

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

.htaccess for Localhost :-

RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
1
  • 1
    The .htaccess for the live server is unchanged from the accepted answer. If there's a good reason to provide a different explanation for the Localhost you should elaborate on that. Dec 27, 2017 at 18:48
0

It is very likely that the administrator of your host has disabled the ability to use Rewrite in .htaccess. They might not even have mod_rewrite installed.

Drop them an email and ask

Since this is a server configuration issue, perhaps you should ask at Server Fault

Edit (since you are sure that the server is configured correctly)

Have you considered tagging your RewriteCond with an end of line $?

RewriteCond $1 !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)

Will (based on my limited knowledge) block any url that contains index.php, css, gfx ... at the start of a url. Because you don't have a $ at the end of the regexp, it will also block any urls that continue on from there...

I.e www.yourdomain.com/index.php/something is not redirected, same with www.yourdomain.com/js/something

Perhaps you want to add a $, which will require the url to end immediately after your regexp.

RewriteCond $1 !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)$
3
  • No. mod_rewrite is on. What I've noticed is that if I change in RewriteRule to /index.php?$1 (question mark instead of forward slash) it goes into an infinite loop. homepage also works when I request index.php directly: example.com/index.php I'm starting to think it might be apache thinking that once the trailing slash is added it is not a file anymore but a folder. how to change such a behaviour?
    – Michal M
    Oct 12, 2009 at 22:28
  • Re your edit. That's the point of not having $ at the end. So that any URLs starting with what's in the brackets are not being rewritten to index.php (inc. index.php and index.php/anything/) otherwise it will not work.
    – Michal M
    Oct 13, 2009 at 7:55
  • Btw. I asked at SeverFault. not much luck there either and less answers/ideas.
    – Michal M
    Oct 13, 2009 at 8:00
0

Here is one time I caught no input file specified right on action:

This causes it:

RewriteRule ^(.*\.swf)$  redirect_php.php/?a=1 [last]

This corrected it:

RewriteRule ^(.*\.swf)$  redirect_php.php?a=1 [last]

note the / before query ?

This seems really related to AcceptPathInfo, which is about the ability to read paths after file names:

http://domain.com/file.php/tricky_path/?regular_query_stuff
0

Since this question seems to attract a lot of attention I'd like to propose another answer for people having encountering the same problem and are unable to solve it with the help of the existing answers. I myself was one of those people until five minutes ago.

Always, I mean always check your server logs because they might present useful information to you.


After checking my server logs (Apache2.4) I found out that open_basedir caused the trouble:

mod_fcgid: stderr: PHP Warning: Unknown: open_basedir restriction in effect. File(/data/sites/domain/public/index.php) is not within the allowed path(s): (/usr/local/lib/php:/usr/local/bin:/data/sites/domain/http-docs) in Unknown on line 0

mod_fcgid: stderr: PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0

In this case, open_basedir could not handle a symbolic link I created because it points to the outside of the open_basedir settings. Either broaden the open_basedir setting to also the new location or move the required files to the inside of any allowed directory..

0

You may be using Nginx, not an Apache. The error message will be the same.

echo out your sever data to be sure.

echo $_SERVER["SERVER_SOFTWARE"];
0

I spent hours trying all recipes from SO until I found the solution: you have to add question mark (?) after ".php", so last line of your rewrite rules will look like:

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

There was no ? In my CodeIgniter setup from previous server, cause it usedpure Apache (no Nginx). And no recipes with port forwarding, nginx reconfiguration or php-fm reinstallation helped -- I tried them all on my VDS.

That simple method solved all in seconds.

0

In my case, the rewrite engine was conflicting with the doc_root directive in php.ini. The rewrite engine was treating the rewritten URL as a local file path and prefixing it with the document root, only to be prefixed again by PHP.

The solution was to rewrite to a relative URL, and add the PT flag. This tells mod_rewrite to pass the result to normal URL processing.

RewriteRule "^/(unwanted-part)/(.*)$" /$2 [PT]
0

In my case I am running laragon it's happening due to php.ini file, then I removed the php and install it again and it worked successfully. I think made some changes in php.ini file that's why it's displaying no input specific. After installing php.ini it fixed my issue.

update php.ini
-1

Maybe your server has AcceptPathInfo disabled that is essential for that kind of URL to work properly. Try to enable it:

AcceptPathInfo On

Ok, try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php(/|$) index.php%{REQUEST_URI} [L]
1
  • 1
    looked promising, but no luck. Error 404: No input file specified.
    – Michal M
    Oct 13, 2009 at 8:10

Your Answer

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

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