简体   繁体   中英

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

Error 404 on linux but work fine on windows. What is causing this?

I use this tutorial: 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';

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.

Live hosting on Linux produces 404 error at url mysite.pro/login.

If I add index.php (mysite.pro/index.php/login), it work fine but I would remove it.

Create .htaccess file in project root directory if other .htaccess file is not already created.

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/

don't forget to restart your server

Hope it helps.

Linux is case sensitive. 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 . Moreover, the first letter of controller/model should be caps (codeigniter requirements). Please check did you write controller/model name correctly.

Update

Put the following snippets on .htaccess file:

<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.
Thank you all for your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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