Linux 上出现 404 错误,但在 Windows 上工作正常。这是什么原因造成的?
我使用这个教程:http://www.tutora.fr/apprendre-codeigniter/les-controleurs
application/config/routes.php:
$route['default_controller'] = 'welcome';
$route['translate_uri_dashes'] = FALSE;
$route['login'] = 'user_authentification/user_authentification';
应用程序/config/config.php:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['subclass_prefix'] = 'CORE_';
Windows 上的本地托管 (XAMPP) 在 url mysite.dev/login 上运行良好。
Linux 上的实时托管在 url mysite.pro/login 处产生 404 错误。
如果我添加
index.php
(mysite.pro/index.php/login),它工作正常,但我会删除它。
Linux 区分大小写。请记住您在哪种情况下编写了目录和文件名。您应该在任何文件中写入与文件或目录所属的名称完全相同的文件或目录名称。
请检查
user_authentification
的文件/目录。此外,控制器/型号的首字母应为大写(codeigniter 要求)。请检查您是否正确填写了controller/model
姓名。
更新
将以下片段放入
.htaccess
文件中:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
管理员已发现错误。虚拟主机出现错误。
.htaccess 文件从未被执行过。
谢谢大家的帮助。
如果尚未创建其他 .htaccess 文件,请在项目根目录中创建 .htaccess 文件。
将以下代码复制粘贴到其中。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /projectname
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
您可以尝试此链接http://addictors.in/remove-index-php-from-url-in-codeigniter/
不要忘记重新启动服务器