codeigniter 3 - 在linux上删除index.php:错误404但在Windows上正常工作

时间:2016-02-17 09:42:04

标签: php linux .htaccess codeigniter

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.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),它可以正常工作,但我会删除它。

3 个答案:

答案 0 :(得分:0)

如果尚未创建其他.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/

不要忘记重新启动服务器

希望它有所帮助。

答案 1 :(得分:0)

Linux区分大小写。请记住,在哪种情况下您编写了目录和文件名。您应该在任何文件或目录所属的文件中写入文件或目录名称。

请检查user_authentification的文件/目录。此外,控制器/模型的第一个字母应该是cap(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>

答案 2 :(得分:0)

管理员发现了错误。虚拟主机出错 .htaccess文件从未执行过 谢谢大家的帮助。