简体   繁体   English

Codeigniter页面在localhost上加载,但在服务器上加载404

[英]Codeigniter page loads on localhost but 404's on server

If I go to: 如果我去:

http://localhost/entry http:// localhost / entry

I see my test page. 我看到我的测试页。 If I go to: 如果我去:

http://examplesite.com/entry http://examplesite.com/entry

I get a 404 page. 我得到一个404页。 And I don't mean the Codeigniter 404 page but the default apache one. 我并不是说Codeigniter 404页面,而是默认的Apache页面。 The code bases are identical. 代码库是相同的。

The homepage works fine but any inner pages 404. This is the contents of my root .htaccess file: 主页可以正常运行,但任何内部页面404都可以。这是我的.htaccess根文件的内容:

<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>

Mod rewrite is enabled on the server verified with phpinfo(). 使用phpinfo()验证的服务器上启用了Mod重写。 Am I missing something? 我想念什么吗?

When you see Apache's 404 status page instead of CodeIgniter's 404 , mod_rewrite is not active. 当您看到Apache的404状态页而不是CodeIgniter的404 ,mod_rewrite不处于活动状态。

phpinfo only tells you, if a module is loaded, not if it's configured properly. phpinfo仅告诉您是否已加载模块,而不告诉您是否已正确配置。 You can check reliably, if mod_rewrite is active, by adding garbage to your .htaccess inside <IfModule mod_rewrite.c>...</IfModule> . 通过在<IfModule mod_rewrite.c>...</IfModule> .htaccess中添加垃圾,可以可靠地检查mod_rewrite是否处于活动状态。 When it is active, you will get a 500 server error. 启用后,您将收到500服务器错误。

To use mod_rewrite in .htaccess files, AllowOverride and Options must be set for the appropriate directory, eg 要在.htaccess文件中使用mod_rewrite ,必须为适当的目录设置AllowOverrideOptions ,例如

AllowOverride FileInfo
Options +FollowSymLinks

or even 甚至

AllowOverride All # default if <= 2.3.8
Options All # this is the default

Unrelated, but %{REQUEST_URI} starts with a slash, so the first two rules (with these RewriteCond s) will never match. 无关,但%{REQUEST_URI}以斜杠开头,因此前两个规则(带有这些RewriteCond )将永远不匹配。

Did you check if the site's base url is set to your local address, if you installed CI on your live site, then chances are your base url is set to that URL. 您是否检查了站点的基本URL是否设置为您的本地地址,如果您在现场站点上安装了CI,那么您的基本URL可能会设置为该URL。 Try verifying it in the config file. 尝试在配置文件中进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM