php .htaccess 问题:未指定输入文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1557258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.htaccess issues: No input file specified
提问by Michal M
Can someone help me with this? I'm feeling like I've been hitting my head against a wall for over 2 hrs now.
有人可以帮我弄这个吗?我感觉我的头撞墙已经超过 2 小时了。
I've got Apache 2.2.8 + PHP 5.2.6installed on my machine and the .htaccesswith the code below works fine, no errors.
我已经Apache 2.2.8 + PHP 5.2.6安装在我的机器上,.htaccess下面的代码工作正常,没有错误。
RewriteEngine on
RewriteCond !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/ [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.
我的托管服务提供商服务器上的相同代码给了我一个 404 错误代码并输出only: No input file specified.index.php 就在那里。我知道他们安装了 Apache(在任何地方都找不到版本信息)并且他们正在运行 PHP v5.2.8。
I'm on Windows XP 64-bit, they're running some Linuxwith PHPin CGI/FastCGImode. Can anyone suggest what could be the problem?
我在Windows XP 64-bit,他们正在运行的一些Linux与PHP在CGI/FastCGI模式。谁能建议可能是什么问题?
PS. if that's important that's for CodeIgniterto work with friendly URLs.
附注。如果这很重要,那就是CodeIgniter使用友好的 URL。
Update1:
更新1:
mod_rewriteis installed and on.
mod_rewrite已安装并打开。
What I've noticed is that if I change in RewriteRuleto /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.
我注意到的是,如果我更改RewriteRule为/index.php?$1(问号而不是正斜杠),它将进入无限循环。无论如何,使用问号不是一种选择,因为CodeIgniter(必需)不会以这种方式工作。
Homepage also works when I request index.php directly: example.com/index.php
当我直接请求 index.php 时,主页也可以工作: 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?
我开始认为它可能是 apache 认为一旦添加了尾部斜杠,它就不再是一个文件而是一个文件夹。如何改变这种行为?
Update 2:
更新 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 Apacheis just not forwarding the query for some reason.
我错了。
Apache 正确处理这些 URL。
请求http://example.com/index.php/start/(主页)或任何其他有效地址有效。
似乎Apache出于某种原因没有转发查询。
Update 3:
更新 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/
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/
回答by jray
I was beating my head up against this as well. I'm also installing Code Igniter.
我也反对这一点。我也在安装 Code Igniter。
The goocher was no RewriteBase. Here's my .htaccess:
goocher 不是 RewriteBase。这是我的.htaccess:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/ [L]
回答by Ynhockey
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:
Zend Framework 给出“未指定输入文件。”,但是:
- 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
- 默认的 RewriteBase 很好,添加
RewriteBase /也没有帮助 - 它是一个共享托管服务器,只有 FastCGI 可用(无法切换到 SuPHP)
- AcceptPathInfo 已开启
- 服务器上的URL重写一般没有问题
So the answer came from the following site: https://ellislab.com/forums/viewthread/55620/P15[dead link] (even though the host is not DreamHost).
所以答案来自以下网站:https: //ellislab.com/forums/viewthread/55620/P15[死链接](即使主机不是 DreamHost)。
The Solution
解决方案
Apparently all you need to do is replace this line:
显然你需要做的就是替换这一行:
RewriteRule ^(.*)$ index.php/
With this:
有了这个:
RewriteRule ^(.*)$ index.php?/
Problem solved.
问题解决了。
回答by A.G.THAMAYS
This worked for me:
这对我有用:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
</IfModule>
After index.php, the question mark is important!
之后index.php,问号很重要!
回答by kkyy
Try if it works with a simpler RewriteCond; like one that rewrites only everything that isn't an existing file/folder/link:
试试看它是否适用于更简单的RewriteCond; 就像只重写不是现有文件/文件夹/链接的所有内容一样:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/ [R,L]
回答by lesocute
Go Daddy Users:
Go Daddy 用户:
- login to your Go Daddy Account
- click on your hosting account.
- go to Settings > File Extensions Management
- change .php and .php5 to run under PHP5.2X (instead of PHP5.2xFastCGI)
- 登录您的 Go Daddy 帐户
- 单击您的主机帐户。
- 转到设置 > 文件扩展名管理
- 将 .php 和 .php5 更改为在 PHP5.2X 下运行(而不是 PHP5.2xFastCGI)
SOLVED!!!!
解决了!!!!
回答by Jay Paroline
mod_rewriteis 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_rewritelike you're trying to redirect to a folder, so it looks for the folder and can't find it, hence the error.
mod_rewrite对于它自己的好处来说有点太聪明了,因为它试图弄清楚它应该做什么类型的重定向。在这种情况下,mod_rewrite您似乎正在尝试重定向到一个文件夹,因此它查找该文件夹但找不到它,因此出现错误。
Edit:Just to be perfectly clear I think your best bet is to change your rewrite rule to:
编辑:为了完全清楚,我认为最好的办法是将重写规则更改为:
RewriteRule ^(.*)$ /index.php? [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.
编辑 2:我看到您已经尝试过了。您获得无限循环的原因是因为您的重写条件中有 index.php。如果您删除它,您应该摆脱无限循环。
回答by Parimal Nakrani
.htaccess for Live Server :-
Live Server 的 .htaccess :-
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/ [L]
.htaccess for Localhost :-
本地主机的 .htaccess :-
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/
回答by Yevgeniy Afanasyev
You may be using Nginx, not an Apache. The error message will be the same.
您可能使用的是 Nginx,而不是 Apache。错误消息将是相同的。
echo out your sever data to be sure.
回显您的服务器数据以确保。
echo $_SERVER["SERVER_SOFTWARE"];
回答by Tom Leys
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.
您主机的管理员很可能已禁用在 .htaccess 中使用重写的功能。他们甚至可能没有安装 mod_rewrite。
Drop them an email and ask
给他们发邮件问问
Since this is a server configuration issue, perhaps you should ask at Server Fault
由于这是服务器配置问题,也许您应该在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?
RewriteCond !^(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...
将(基于我有限的知识)阻止任何包含 index.php、css、gfx ... 在 url 开头的 url。因为在正则表达式的末尾没有 $,它还会阻止从那里继续的任何 url...
I.e www.yourdomain.com/index.php/somethingis not redirected, same with www.yourdomain.com/js/something
即www.yourdomain.com/index.php/something没有重定向,与www.yourdomain.com/js/something
Perhaps you want to add a $, which will require the url to end immediately after your regexp.
也许您想添加一个 $,这将要求 url 在您的正则表达式之后立即结束。
RewriteCond !^(index\.php|css|gfx|js|swf|robots\.txt|favicon\.ico)$
回答by halfpastfour.am
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 alwayscheck 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:
检查我的服务器日志(Apache2.4)后,我发现 open_basedir 导致了问题:
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
mod_fcgid:stderr:PHP 警告:未知:open_basedir 限制生效。文件(/data/sites/domain/public/index.php)不在允许的路径内:(/usr/local/lib/php:/usr/local/bin:/data/sites/domain/http -docs) 在第 0 行的未知
mod_fcgid:stderr:PHP 警告:未知:无法打开流:在第 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..
在这种情况下,open_basedir 无法处理我创建的符号链接,因为它指向 open_basedir 设置的外部。要么将 open_basedir 设置扩展到新位置,要么将所需文件移动到任何允许的目录中。

