只有主页显示所有其他页面在 xampp codeigniter 中显示错误 404

Posted

技术标签:

【中文标题】只有主页显示所有其他页面在 xampp codeigniter 中显示错误 404【英文标题】:only home page is showing all other pages is showing error 404 in xampp codeigniter 【发布时间】:2017-03-12 17:03:27 【问题描述】:

我正在使用 CODEIGNITER。我安装了一个可以在线正常工作的项目,但是当我在本地主机(XAMPP)中复制文件时,只有主页是工作文件,所有其他页面都显示以下消息:

未找到 在此服务器上未找到请求的 URL /maharajaviaggi/team。 此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。 Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8h mod_autoindex_color php/5.2.6 服务器在 localhost 端口 80

我不明白为什么它会显示这个,因为它在网上运行良好......?

【问题讨论】:

在配置文件中检查你的 base_url()。 检查你的文件和类名有没有读过这个codeigniter.com/user_guide/general/styleguide.html#file-naming 【参考方案1】:

如果问题与 htaccess 相关

如果你在 apache 上使用 php 作为模块,你的 .htaccess 应该是这样的

RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]

如果您将其用作 cgi 或 fpm

RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

【讨论】:

这显示在错误服务器错误下方!服务器遇到内部错误,无法完成您的请求。服务器过载或 CGI 脚本中存在错误。如果您认为这是服务器错误,请联系网站管理员。错误 500 localhost 10/30/16 17:16:14 Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8h mod_autoindex_color PHP/5.2.6【参考方案2】:

确保 index.php 旁边的 .htaccess 文件看起来像这样:

RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule .* index.php/$0 [PT,L]

然后转到您的配置,并将这些行更改为:

$config['base_url'] = 'http://localhost/your_project_name/';  
$config['index_page'] = '';

【讨论】:

下面显示错误服务器错误! 服务器遇到内部错误,无法完成您的请求。服务器过载或 CGI 脚本中存在错误。如果您认为这是服务器错误,请联系网站管理员。错误 500 localhost 10/30/16 17:16:14 Apache/2.2.9 (Win32) DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8h mod_autoindex_color PHP/5.2.6 检查是否有多个 .htaccess 文件并且它们都一样,它们可能在你的 codeigniter 应用程序中更多。 是的,我在根级别有一个带有应用程序文件夹的 .htaccess。第二个是在应用程序文件夹内。 #Deny from all RewriteEngine On #RewriteBase / RewriteCond %REQUEST_URI ^system.* RewriteRule ^(.*)$ index.php/$1 [L] RewriteCond %REQUEST_FILENAME !-f RewriteCond % REQUEST_FILENAME !-d #最后一个条件允许访问 images 和 css 文件夹,以及 robots.txt 文件 RewriteCond $1 !^(index\.php|(.*)\.swf|images|robots\.txt|css |docs|cache) RewriteRule ^(.*)$ index.php/$1 [L] 可能是您的 xampp 安装出错,请尝试检查 mod rewrite 模块是否处于活动状态并正在运行。如果没有任何效果,请卸载 xampp 并尝试使用 wamp。 然后是你的类名,确保类的首字母大写,并确保文件首字母大写。不能是别的。

以上是关于只有主页显示所有其他页面在 xampp codeigniter 中显示错误 404的主要内容,如果未能解决你的问题,请参考以下文章