简体   繁体   English

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

[英]codeigniter 3 - remove index.php : error 404 on linux but work fine on windows

Error 404 on linux but work fine on windows. Linux上的错误404,但在Windows上工作正常。 What is causing this? 是什么造成的?

I use this tutorial: http://www.tutora.fr/apprendre-codeigniter/les-controleurs 我使用本教程: http//www.tutora.fr/apprendre-codeigniter/les-controleurs

application/config/routes.php : application / config / routes.php:

$route['default_controller'] = 'welcome';
$route['translate_uri_dashes']  = FALSE;
$route['login'] = 'user_authentification/user_authentification';

application/config/config.php: 的application / config / config.php文件:

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['subclass_prefix'] = 'CORE_';

Local hosting on Windows (XAMPP) works fine at url mysite.dev/login. Windows上的本地托管(XAMPP)在url mysite.dev/login上运行良好。

Live hosting on Linux produces 404 error at url mysite.pro/login. Linux上的实时托管在url mysite.pro/login上产生404错误。

If I add index.php (mysite.pro/index.php/login), it work fine but I would remove it. 如果我添加index.php (mysite.pro/index.php/login),它工作正常,但我会删除它。

Create .htaccess file in project root directory if other .htaccess file is not already created. 如果尚未创建其他.htaccess文件,请在项目根目录中创建.htaccess文件。

copy paste below codes into it . 将代码粘贴到代码下面。

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

You can try this link http://addictors.in/remove-index-php-from-url-in-codeigniter/ 你可以尝试这个链接http://addictors.in/remove-index-php-from-url-in-codeigniter/

don't forget to restart your server 别忘了重启服务器

Hope it helps. 希望能帮助到你。

Linux is case sensitive. Linux区分大小写。 Keep in mind in which case you wrote the directory and file name. 请记住,在哪种情况下您编写了目录和文件名。 You should write file or directory name in any file exactly same what file or directory belongs. 您应该在任何文件或目录所属的文件中写入文件或目录名称。

Please check the file/directory of user_authentification . 请检查user_authentification的文件/目录。 Moreover, the first letter of controller/model should be caps (codeigniter requirements). 此外,控制器/模型的第一个字母应该是cap(codeigniter要求)。 Please check did you write controller/model name correctly. 请检查您是否正确编写了controller/model名称。

Update 更新

Put the following snippets on .htaccess file: 将以下片段放在.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>

The administrator has found the error. 管理员发现了错误。 There was an error in virtual host. 虚拟主机出错。
The .htaccess file was never executed. .htaccess文件从未执行过。
Thank you all for your help. 感谢大家的帮助。

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

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