Codeigniter页面在localhost上加载,但在服务器上加载404 [英] Codeigniter page loads on localhost but 404's on server
问题描述
如果我要访问:
我看到了我的测试页。如果我要访问:
I see my test page. If I go to:
我得到一个404页面。我不是说Codeigniter 404页面,而是默认的Apache页面。代码库是相同的。
I get a 404 page. And I don't mean the Codeigniter 404 page but the default apache one. The code bases are identical.
首页可以正常运行,但任何内部页面404都可以。这是我的根.htaccess文件的内容:
The homepage works fine but any inner pages 404. This is the contents of my root .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes access to the system folder by users. Additionally this will allow you to create a System.php controller, '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. Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Checks to see if the user is attempting to access a valid file, such as an image or css document, if this isn't true it sends the request to index.php.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
在通过phpinfo()验证的服务器上启用了模块重写。我缺少什么吗?
Mod rewrite is enabled on the server verified with phpinfo(). Am I missing something?
推荐答案
当您看到Apache的 404
状态页面时而不是CodeIgniter的 404
,mod_rewrite不处于活动状态。
When you see Apache's 404
status page instead of CodeIgniter's 404
, mod_rewrite is not active.
phpinfo
仅告诉您是否已加载模块,而不是已配置正确地。如果 mod_rewrite
是活动的,则可以通过在< IfModule mod_rewrite.c> ...< / IfModule>
。启用后,您会收到 500
服务器错误。
phpinfo
only tells you, if a module is loaded, not if it's configured properly. You can check reliably, if mod_rewrite
is active, by adding garbage to your .htaccess inside <IfModule mod_rewrite.c>...</IfModule>
. When it is active, you will get a 500
server error.
要使用 mod_rewrite
.htaccess 文件, AllowOverride
和 选项
必须为相应的目录设置,例如
To use mod_rewrite
in .htaccess
files, AllowOverride
and Options
must be set for the appropriate directory, e.g.
AllowOverride FileInfo
Options +FollowSymLinks
甚至
AllowOverride All # default if <= 2.3.8
Options All # this is the default
不相关,但 %{REQUEST_URI}
开头为斜线,因此前两个规则(带有这些 RewriteCond
s)将永远不匹配。
Unrelated, but %{REQUEST_URI}
starts with a slash, so the first two rules (with these RewriteCond
s) will never match.
这篇关于Codeigniter页面在localhost上加载,但在服务器上加载404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!