繁体   English   中英

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

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

如果我去:

http:// localhost / entry

我看到我的测试页。 如果我去:

http://examplesite.com/entry

我得到一个404页。 我并不是说Codeigniter 404页面,而是默认的Apache页面。 代码库是相同的。

主页可以正常运行,但任何内部页面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>

使用phpinfo()验证的服务器上启用了Mod重写。 我想念什么吗?

当您看到Apache的404状态页而不是CodeIgniter的404 ,mod_rewrite不处于活动状态。

phpinfo仅告诉您是否已加载模块,而不告诉您是否已正确配置。 通过在<IfModule mod_rewrite.c>...</IfModule> .htaccess中添加垃圾,可以可靠地检查mod_rewrite是否处于活动状态。 启用后,您将收到500服务器错误。

要在.htaccess文件中使用mod_rewrite ,必须为适当的目录设置AllowOverrideOptions ,例如

AllowOverride FileInfo
Options +FollowSymLinks

甚至

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

无关,但%{REQUEST_URI}以斜杠开头,因此前两个规则(带有这些RewriteCond )将永远不匹配。

您是否检查了站点的基本URL是否设置为您的本地地址,如果您在现场站点上安装了CI,那么您的基本URL可能会设置为该URL。 尝试在配置文件中进行验证。

暂无
暂无

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

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